Rob Spector
Rob Spector

Reputation: 5

Suitescript 2.0 Client Script Hanging

I am failing to develop a client script that will check the value of the unitcost line field on inventory adjustments. We have issues internally with inventory adjustments being done with no value.

Below is my code, when deployed it causes the inventory adjustment transaction record to hang.

define(['N/record','N/search','N/ui/dialog', 'N/log'], /** *@NApiVersion 2.0 *@NScriptType ClientScript */ function saveRecord(currentRecord) {

  var lines = currentRecord.getLineCount({sublistId:'inventory'})
  for (var i = 0; i <= lines; i++){
    if (currentRecord.getSublistValue({sublistId: "inventory",fieldId:"unitcost",line:i} == 0.00)) {
        dialog.alert({
            title: 'estimated unit cost error',
            message: 'Enter Estimated Unit Cost!! This should not be $0.00'
        });
        return false;
    } else {
        return true;
    }
  }

return {
    
    saveRecord: saveRecord
}

});

I have tried the referenced code above expecting to get a dialog box and the record submit to be cancalled, instead the record form hangs while trying to load the inventory sublist (transaction lines).

Upvotes: 0

Views: 222

Answers (2)

Krypton
Krypton

Reputation: 5276

Not sure if this would cause the script to hang, but you appear to be passing the context for the saveRecord function incorrectly. You declare function saveRecord(currentRecord) and then use currentRecord as if it is an instance of a NetSuite record.Record object.

However, the object passed into the saveRecord entry point is actually a context record. It contains the current record object as a nested object, but is not itself the current record.

...
function saveRecord(context) {
    var lines = context.currentRecord.getLineCount({sublistId:'inventory'});
...

Also open your browser console to check for any error messages there when you run this script (IE: when you save the record it's deployed on).

Upvotes: 0

bknights
bknights

Reputation: 15447

It looks like you may have mixed SS1 and SS2 samples. The line: for (var i = 0; i <= lines; i++){ should be: for (var i = 0; i < lines; i++){

because SS2 uses 0 based indexing. so for 3 lines your indexes are 0, 1, 2

Upvotes: 0

Related Questions