i have been trying this for many days there seems ...
# suitescript
r
i have been trying this for many days there seems to be no solution
t
So you are trying to set a line value with "InsertSelection"?
or are you trying to add options to the field's list of options?
You can't add values to a field on a form on the client side in this manner to my knowledge. Netsuite limitation
b
not sure which field you are trying to work with
if its a native one, you cant insert select options
if its a custom one, you can use CurrentRecord.getSublistField , though you may have to deal with the annoyance that ss2 made the line mandatory
r
I am trying through getsublistfield but it's not available
For fieldchanged and postsourcing
Because I want to filter based on item and vendor present on line level , I am creating a custom field in beforeLoad and trying filter there. But it's not happening
b
huh
what does your code look like
r
I am not able to getSublisTfireld because it won't work fieldchanged
b
usually you need to do better than not working for usable advice
r
Copy code
define(["N/ui/serverWidget","N/search","N/runtime"], function (serverWidget,search,runtime) {
    function setCustomSelectField(context) {
     var currentRec=context.newRecord;
      //Get Object of the sublist
      var sublist = context.form.getSublist({
        id: "item",
      });
  //Add field into the Sublist which object is identified
    var field=sublist.addField({
        id: "custpage_skulist",
        type: serverWidget.FieldType.SELECT,
        label: "SKU List"
     
      });
     
    }
  
    return {
      beforeLoad: setCustomSelectField,
    };
  });
look this is the userevent
Copy code
define(["N/search", "N/runtime", "N/ui/dialog"], function (
  search,
  runtime,
  dialog
) {
  function fieldChanged(context) {
    try {
      //get Current record context
      var currentRec = context.currentRecord;
      //get the field and sublist that causing the Event
      var sublistName = context.sublistId;
      var fieldId = context.fieldId;
      //Check if desire field is triggering event
      if (sublistName == "item") {
        //Check first Vendor is selected or Not
        //As Vendor is very key for search we need it for proper flow
        var vendorSelected = currentRec.getCurrentSublistValue({
          sublistId: "item",
          fieldId: "povendor",
        });
        
        var itemSelected = currentRec.getCurrentSublistValue({
          sublistId: "item",
          fieldId: "item",
          // line:0
        });

        if (itemSelected != "" && vendorSelected != "") {
          //get the list of SKU units related to the Vendor
          var customrecordSearchObj = search.create({
            type: "customrecord389",
            filters: [
              ["custrecord155", "anyof", parseInt(vendorSelected)],
              "AND",
              ["custrecord156", "anyof", parseInt(itemSelected)],
            ],
            columns: [
              search.createColumn({
                name: "name",
                sort: search.Sort.ASC,
                label: "Name",
              }),
              search.createColumn({ name: "id", label: "ID" }),
              search.createColumn({ name: "custrecord156", label: "Item" }),
            ],
          });

          var SKUSearch = searchAll(customrecordSearchObj.run());

          var skuListObj = currentRec.getSublistField({
            fieldId: "custpage_skulist",
            sublistId: "item",
            line: 0,
          });
          //     //check weather the entered entry is in SKU unit list
          var index = 0;

          // var skuInternalId=SKUSearch[i].getValue({name: "id", label: "ID"});
          skuListObj.removeSelectOption({
            value: null,
          });

          for (var i = 0; i < SKUSearch.length; i++) {
            var SKURelated = SKUSearch[i].getValue({
              name: "name",
              label: "Name",
            });
            var skuInternalId = SKUSearch[i].getValue({
              name: "id",
              label: "ID",
            });
            if (!SKURelated == "") {
              skuListObj.insertSelectOption({
                value: skuInternalId,
                text: SKURelated,
              });
            }
          }
        }
      }
      return true;
    } catch (e) {
      log.error({
        title: "Error",
        details: e,
      });
    }
    return true;
  }
  //Function for set value from Scripted field to SKU Field And Save Record
  function saveRecord(context) {
    try {
      //get Current record context
      var currentRec = context.currentRecord;
      //Get Line count Entered by user
      var length = currentRec.getLineCount({
        sublistId: "item",
      });

      for (var i = 0; i < length; i++) {
        //Set Value from scripted field to SKU field
        currentRec.selectLine({ sublistId: "item", line: i });
        var skuListValue = currentRec.getCurrentSublistValue({
          fieldId: "custpage_skulist",
          sublistId: "item",
        });

        currentRec.setCurrentSublistValue({
          fieldId: "custcol1",
          sublistId: "item",
          value: skuListValue,
        });
        currentRec.commitLine({ sublistId: "item" });
      }

      return true;
    } catch (e) {
      log.error({
        title: "Error",
        details: e,
      });
    }
    //search function
  }
  function searchAll(resultsetCurrent) {
    var allResults = [];
    var startIndex = 0;
    var RANGECOUNT = 1000;
    do {
      var pagedResults = resultsetCurrent.getRange({
        start: parseInt(startIndex),
        end: parseInt(startIndex + RANGECOUNT),
      });
      allResults = allResults.concat(pagedResults);
      var pagedResultsCount = pagedResults != null ? pagedResults.length : 0;
      startIndex += pagedResultsCount;
      var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
    } while (pagedResultsCount == RANGECOUNT);
    var remainingUsage = runtime.getCurrentScript().getRemainingUsage();
    return allResults;
  }
  return {
    lineInit: fieldChanged,
    saveRecord: saveRecord,
  };
});
client script
b
im guessing your code would work for every line but the first