anyone got time to take a second look at a Client ...
# suitescript
i
anyone got time to take a second look at a Client Script that I can't get finalized. It's a client script on a Transfer Order and is triggered off a button. I am replacing the item with another item for all the items on the order. on my execution logs all the values are correct however when setting the line and committing the line it only does it for the last one. I have also tried to remove all the lines and set them as new line items and still the same issue only one item gets added.
Copy code
for (var x = 1; x <= itemCount; x++) {
        var itemId2 = 0;

        itemId2 = nlapiGetLineItemValue('item', 'item', x);
        nlapiLogExecution('DEBUG', 'iter | baseItem | napaItem', x +' | '+napaItems[itemId2].baseNumber+' | '+napaItems[itemId2].napaItem);


        nlapiSelectLineItem('item', x);
        nlapiSetCurrentLineItemValue('item', 'item', napaItems[itemId2].napaItemId);
        nlapiSetCurrentLineItemValue('item', 'custcol_to_adj_item_interchange', napaItems[itemId2].baseNumberId);
        nlapiCommitLineItem('item');
    }
c
I've done a substitute items script. I found it easier to work in standard mode rather than dynamic.
I only know SuiteScript 2 so can't comment on what your code is doing but I did this
Copy code
const itemCount =  record.getLineCount('item')

record.insertLine({
    sublistId: 'item',
    line: itemCount
});

record.setSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    value: id,
    line: lineCount
})
This ensures that I'm always adding the new item to the end of the sublist
then I used record.findSublistLineWithValue() to find the old item and remove it.
i
thanks, gonna come back to it in the morning. If I still can't get it to work going to try the SS2 route.
c
@Israel Gonzalez I would only consider SS2. If you're writing SS1 for new scripts, you're just creating technical debt.
i
@Craig Yeah for new scripts I use SS2, this was an existing SS1 script that was supposed to be a quick edit.
b
i
@battk thanks that did it, i had tried doing true,true for the firefieldchanged and synchronuous but that didn't work. doing false,true ended up working as expected