skip to Main Content

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).

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search