RE: SuiteScript 1.0 Commit Line on Client Script not commiting line

Hi all,

We are having issues when using the commit line API call to add a new line to sublists on our Sales Order. The commit line is being called in asynchronous code.

After the api call, the line is not fully committed. The field values are populated, but the user must still click the ‘Add’ button to commit the line manually.

This is my code:

function recalc(type)
{

if(type == ‘item’)
{
var itemId = nlapiGetCurrentLineItemValue(‘item’, ‘quantity’);
if(itemId > 100)
{

//Insert item
nlapiSelectNewLineItem(‘item’);
nlapiSetCurrentLineItemValue(‘item’, ‘item’, “REV0007”);
nlapiSetCurrentLineItemValue(‘item’, ‘quantity’, 1);
nlapiCommitLineItem(‘item’);

}
}
return true;
}

 

Thanks

Gaston Rookie Asked on May 7, 2023 in SuiteScript.
Add Comment
1 Answers

It seems like the issue might be related to the asynchronous code you are using to call the commitLineItem function. In asynchronous code, the API call might not complete before the function returns, which could result in the line not being fully committed.

To address this, you can use a callback function to ensure that the commitLineItem call completes before moving on to the next step. Here’s an example of how you can modify your code to use a callback function:

function recalc(type) {
if (type == 'item') {
var itemId = nlapiGetCurrentLineItemValue('item', 'quantity');
if (itemId > 100) {
// Insert item
nlapiSelectNewLineItem('item');
nlapiSetCurrentLineItemValue('item', 'item', 'REV0007');
nlapiSetCurrentLineItemValue('item', 'quantity', 1);
nlapiCommitLineItem('item', commitCallback);
}
}
return true;
}
function commitCallback(line) {
// Line has been fully committed, continue with the next step
}

 

 

In this code, we’re passing a callback function (commitCallback) as the second argument to the nlapiCommitLineItem function. This function will be called once the line has been fully committed. You can use this function to move on to the next step in your code once the line has been fully committed.

 

 

 

 

 

 

Beginner Answered on May 11, 2023.

Thank you very much, I’m going to try your solution and then I’ll tell you how it turned out. Thanks again!!

on May 11, 2023.

Hi, I was not lucky, I still cannot confirm the line, I have tried everything but I have not succeeded. Do you have another idea? I tried with promotions and it works by adding lines, but by script I can not achieve it.

on May 11, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.