Hello, I am trying to set a line value for a sales...
# suitescript
p
Hello, I am trying to set a line value for a sales order line after the sales order has been initially created. When I have a sales order with four or more lines the script does not work. What am I doing wrong?
b
expect to share more code, especially whatever you use for looping
p
for (var x = 0; x < lines; x++) { //for loop var numbertoset2 = x+1; numbertoset2 = parseInt(numbertoset2); var n2 = numbertoset2.toString(); soRecord.setSublistValue({ sublistId : 'item', fieldId : 'custcol_kit_number', line : x, saveneeded='1'; } // end of for loop /*soRecord.setValue({ fieldId : 'custbody_pi_renumkitnum', value : false});*/ log.debug({details:"gothere = " + saveneeded}); if (saveneeded === '1') { var recId= soRecord.save({ enableSourcing: true, ignoreMandatoryFields: true }); log.debug({details:"savedrecord" + recId}); }
there is the code
b
still need to share what lines is
p
var soRecord = record.load({ type: record.Type.SALES_ORDER, id: recordId }); //Get the number of line items var lines = soRecord.getLineCount({ sublistId: 'item' });
a
This is not valid...
p
I fixed it: var numbertoset2 = x+1; numbertoset2 = parseInt(numbertoset2); var n2 = numbertoset2.toString(); soRecord.setSublistValue({ sublistId : 'item', fieldId : 'custcol_kit_number', line : x, value : n2}); saveneeded='1';
a
Untitled
p
the problem is the kit number is not being set when the sales order has four lines
a
Also be careful with
parseInt(numbertoset2);
without radix.
p
what is radix?
p
thanks. the kit number sets fine when I have one or two lines but it does not set anything in the field when there are four lines. I run the debugger and I can see the correct values are set
a
Can you set that value in the UI for that Order with 4 lines?
p
yes. you can
b
your code is fine, if ugly looking
nothing in there would specifically fail at 4 lines
in my account, it works normally for an order with 4 lines
p
its weird. I can not get it to work in mine
b
you can try taking a look at user event scripts or workflows deployed to sales orders to see if they are causing issues
the code i used looks like
Copy code
require(["N/record"], function (record) {
  var soRecord = record.load({
    type: record.Type.SALES_ORDER,
    id: "28446",
  });
  //Get the number of line items
  var lines = soRecord.getLineCount({
    sublistId: "item",
  });

  for (var x = 0; x < lines; x++) {
    //for loop
    var numbertoset2 = x + 1;
    numbertoset2 = parseInt(numbertoset2);
    var n2 = numbertoset2.toString();
    soRecord.setSublistValue({
      sublistId: "item",
      fieldId: "custcol_kit_number",
      line: x,
      value: n2,
    });
    saveneeded = "1";
  } // end of for loop
  log.debug({ details: "gothere = " + saveneeded });
  if (saveneeded === "1") {
    var recId = soRecord.save({
      enableSourcing: true,
      ignoreMandatoryFields: true,
    });
    log.debug({ details: "savedrecord" + recId });
  }
});
a
Kit Items and Group Items behave weird at the line level and they may be adding weird lines... you need to check if that is the case...
p
got it. we do have kit items on the so
I did get it working. thanks for your help
l
@Phillip Do you mind sharing how you got it working? I can imagine needing to do something similar in the future and getting stuck on this.
p
I made a change to our integration process to populate the checkbox when the salesorder is created. the sales order was being updated multiple times