when i call commitline function in validateline th...
# ask-stanley-ai
n
when i call commitline function in validateline the script executes the code in the initial index and not the next in suitescript how can i fix this
c
AI generated answer (using internal Slack threads):
It seems like you're having an issue with the
commitLine
function in the
validateLine
context. The
commitLine
function is used to save the current sublist line being edited in dynamic mode. If you're finding that the script is executing the code in the initial index and not the next, it might be because you're not correctly incrementing the line index after each
commitLine
call. Here's a general example of how you might structure your code:
Copy code
javascript
require(['N/currentRecord'], function(currentRecord){
  var scriptContext = {currentRecord: currentRecord.get()};
  var lineCount = scriptContext.currentRecord.getLineCount({sublistId: 'item'});
  
  for (var i = 0; i < lineCount; i++) {
    scriptContext.currentRecord.selectLine({sublistId: 'item', line: i});
    console.log('idx', scriptContext.currentRecord.getCurrentSublistIndex({sublistId: 'item'}));

    scriptContext.currentRecord.setCurrentSublistValue({
      sublistId: 'item',
      fieldId: 'taxcode',
      value: 316
    });

    scriptContext.currentRecord.commitLine({sublistId: 'item'});
  }
});
In this example,
lineCount
is used to get the total number of lines in the sublist. The
for
loop then iterates over each line, selecting it with
selectLine
, setting a value with
setCurrentSublistValue
, and then committing the line with
commitLine
. After each iteration, the index
i
is incremented, moving to the next line. Remember, this is a general example and you might need to adjust it to fit your specific needs. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824829102
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.818481505
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.817016661
Please provide your feedback on this answer.