Hello, Can somebody help me with one question: I’v...
# suitescript
i
Hello, Can somebody help me with one question: I’ve implemented client script (2.0 API save record entry). It works with the Item Receipt, iterates through each item line, reads subrecord Inventory Detail and it’s sublist “inventoryassignment”, which has field “Bin”. I have no problems with reading BIN value or text, but I simply can’t get Bin Field. How can I get this field options right way? Code sample in the thread.
Copy code
function saveRecord(scriptContext) {
 var rec = scriptContext.currentRecord;
 var itemLineCount = rec.getLineCount({
  sublistId: "item"
 });

 if (itemLineCount > 0) {
  for (var lineNum = 0; lineNum < itemLineCount; lineNum++) {
   //selecting lines in the Item Receipt
   rec.selectLine({
    sublistId: "item",
    line: lineNum
   });
   //check if line has subrecord
   if (!rec.hasCurrentSublistSubrecord({
     sublistId: "item",
     fieldId: "inventorydetail"
    })) {
    continue;
   }
   //get Inventory Detail form with target value (Bin)
   var invDetDyn = rec.getCurrentSublistSubrecord({
    sublistId: "item",
    fieldId: "inventorydetail"
   });
   //iterating through lines in Inventory detail
   var lineInInvDet = 0;
   while (true) {
    /* Impossible to get number of lines on the subrecord. Possible reason is that the currentRecord is in the dynamic mode
     * try...catch used for catching cases, when we considered every line. Non existing line throws an error.
     */
    try {
     invDetDyn.selectLine({
      sublistId: "inventoryassignment",
      line: lineInInvDet
     });
    } catch (error) {
     //no more lines in the Inventory Detail form
     break;
    }
    // getting bin value with no problems
    var binValue = invDetDyn.getCurrentSublistValue({
     sublistId: "inventoryassignment",
     fieldId: "binnumber"
    });

    var binField = invDetDyn.getSublistField({
     sublistId: "inventoryassignment",
     fieldId: "binnumber",
     line: lineInInvDet
    });
    // inside the console log I can see the field, but most
    // of it's values are undefined.
    //the most interesting for me is the getSelectOptions,
    // which should allow me to get all options
    console.log(binField);
    lineInInvDet++;
   }
  }
 }
 return true;
}