I am trying to create a small script that will val...
# administration
t
I am trying to create a small script that will validate line items on an Inventory Adjustment record to check that the Header level's "Adjustment Location" matches the Line level's Location field. We want to have an alert pop up once a line has been entered to enforce that they are always the same. I'm stuck and looking for advice. I'll post the code I'm using, along with a screenshot if anyone is willing to give advice on what I am doing wrong.
message has been deleted
/**
* @NApiVersion 2.0 * @NScriptType ClientScript * @NModuleScope SameAccount * */ define(['N/currentRecord'], function(currentRecord) { var isEdit = false; /** * Validation function to be executed when sublist line is committed. * * @param {Object} scriptContext * @param {Record} scriptContext.currentRecord - Current form record * @param {string} scriptContext.sublistId - Sublist name * * @returns {boolean} Return true if sublist line is valid * * @since 2015.2 */ function validateLine(scriptContext) { var currRec = currentRecord.get(); //retrieve the current record to collect values var headerLocation = currRec.adlocation; //capture header level location var lineLocation = currRec.getCurrentSublistValue({ sublistId: 'inventory', fieldId: 'location' }); //capture line level location console.log(headerLocation); console.log(lineLocation); // if (isEdit == true && headerLocation != null && headerLocation != undefined && headerLocation != '' && headerLocation =! lineLocation) { // alert('This inventory line location must match the Adjustment Location for this adjustment. These must match to avoid this error.'); // return false; // } return true; } return { validateLine: validateLine, }; });
m
First thing: I think this is the correct way to get the currentRecord
Copy code
var currRec = context.currentRecord;
recommend you to check out the help documentation. app/help/helpcenter.nl?fid=section_4387798404.html#bridgehead_4484779426