jrhoads23
jrhoads23

Reputation: 59

NetSuite Mass Update script runs sucessfully, but nothing gets updated

Have been a developer for years, but just getting into NetSuite scripting. I wanted to start simple and create a script that would update the COMMENT field for all items on a purchase order. I started off by following the tutorial found here.

My modified script is below - it should update the MEMO field at the PO header and then every line's COMMENT field. I followed the steps in the article to save the script, create a Mass Update and then run it. In my criteria I set: "Transaction Number/ID" and "has keyword 90999" (just so it would only run on one specific purchase order). I confirmed my criteria was correct by clicking "Preview" and it only returns that one PO.

When I run the Mass Update, it runs fine and says it has been run successfully on 1 record (which is good). The MEMO field at the PO header DOES get updated, but the COMMENT field for each line does not. Am I doing something wrong or missing something simple? Is the getLineCount call not the correct one to use?

Note that I was doing all this in our Sandbox environment in case that makes any difference

UPDATE: I know the getLineCount call is returning the correct number because if I move the poRec.setValue call inside the for loop, it gets run. So something must be wrong with my poRec.setSublistValue call?

/**
*@NApiVersion 2.0
*@NScriptType MassUpdateScript
*/
define(['N/record'],
function (record) {
function each(params) {
    // Need to LOAD each record and SAVE it for changes to take effect
    // LOAD the PO
    var poRec = record.load({
        type: params.type,
        id: params.id
    });

    //var mainDepartment = poRec.getValue('department');
    var mainDepartment = 'Hello World';

    poRec.setValue({
        fieldId: 'memo',
        value: mainDepartment
    });

    // get a count of the line items
    var lineCount = poRec.getLineCount({
        sublistId: 'item'
    });

    // go through each of the line items and set the department to the main level department
    for (var i = 0; i < lineCount; i++) {
        poRec.setSublistValue({
            sublistId: 'item',
            fieldId: 'comment',
            line: i,
            value: mainDepartment
        });
    }

    // SAVE the PO
    poRec.save();
}
return {
    each: each
};
});

Upvotes: 0

Views: 810

Answers (1)

bknights
bknights

Reputation: 15402

There is no 'comment' field on the item sublist. The field you probably mean is 'description' (which expresses on searches as the line level 'memo' field - Netsuite for the win!)

Upvotes: 0

Related Questions