<@U5TF1GQ20> This is in response to my earlier pos...
# suitescript
r
@battk This is in response to my earlier post where I was trying to get a client script to scan through all the inventory detail subrecords and throw an error in case any record is missing bin number. You had asked for my code and somehow I had missed that comment, my apologies. Reposting as the eariler post is not visible anymore. All I need to do here is throw an error if any of the inventory detail subrecord on the item receipt has data in status and quantity fields but has left the bin field empty, it should not allow the record to be saved (screenshot attached). The count is returning -1 every time. Please find the code below: /** * @NApiVersion 2.x * @NScriptType ClientScript * @NModuleScope SameAccount */ define(['N/record','N/search','N/ui/dialog'], function(record, search, dialog) { function saveRecord(scriptContext) { var rec = scriptContext.currentRecord; rec.selectNewLine({ sublistId: 'item' }); subrecordInvDetail = rec.getCurrentSublistSubrecord({ sublistId: 'item', fieldId: 'inventorydetail' }); var numLines = subrecordInvDetail.getLineCount('inventorydetail'); var myInventoryNumber = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'binnumber' }); var myqty = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'quantity' }); var mystatus = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'inventorystatus' }); dialog.alert({ title: 'Warning', message: 'count ='+numLines }); if(myInventoryNumber !== null) { } else { dialog.alert({ title: 'Warning', message: 'Cannot leave bin number empty ' }); } } return { saveRecord: saveRecord } });
c
This line
if(myInventoryNumber !== null) {
-- I would dump
myInventoryNumber
and check what its value is.
undefined
!==
null
is true, for example
b
there are a lot of weird things going on with that code
id start with trying to use Column.isMandatory over trying to do mandatory in code
will involve deploying your client script on the inventory detail
r
@battk I tried but column.ismandatory is not working so far, I noticed another thing after putting in debugging messages that the above script is getting executed from bottom up, is that normal? i cant seem to be able to find any related documentation
b
what does your code look like now?
r
similar to the previous one but with a lot of messages and they are getting executed backwards, for example 15 then 14ELSE, 13...
/**
* @NApiVersion 2.x * @NScriptType ClientScript * @NModuleScope SameAccount */ define(['N/record','N/search','N/ui/dialog'], function(record, search, dialog) { function saveRecord(scriptContext) { dialog.alert({ title: 'Warning', message: '>1'}); var rec = scriptContext.currentRecord; dialog.alert({ title: 'Warning', message: '>2'}); rec.selectNewLine({ sublistId: 'item' }); dialog.alert({ title: 'Warning', message: '>3'}); subrecordInvDetail = rec.getCurrentSublistSubrecord({ sublistId: 'item', fieldId: 'inventorydetail' }); dialog.alert({ title: 'Warning', message: '>4'}); /*subrecordInvDetail.selectLine({ sublistId: 'inventoryassignment', line: 0 });*/ //var numLinesasg = subrecordInvDetail.getLineCount('inventoryassignment'); /* var numLines = subrecordInvDetail.getCurrentSublistIndex({ sublistId: 'inventorydetail' });*/ // for (var i=1; i<=numberOfLineItems; i++){ /* console.log('CHECK Msg 1A- myInventoryNumber='+myInventoryNumber+' qty= '+myqty+ ' status= '+mystatus);*/ /*dialog.alert({ title: 'Warning', message: 'CHECK Msg 1A- myInventoryNumber='+myInventoryNumber+' qty= '+myqty+ ' status= '+mystatus}); */ dialog.alert({ title: 'Warning', message: '>5'}); var myInventoryNumber = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'binnumber', line: 0 }); dialog.alert({ title: 'Warning', message: '>6'}); var myqty = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'quantity', line: 0 }); dialog.alert({ title: 'Warning', message: '>7'}); var mystatus = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'inventorystatus', line: 0 }); dialog.alert({ title: 'Warning', message: '>8'}); /*dialog.alert({ title: 'Warning', message: 'CHECK Msg 1B- myInventoryNumber='+myInventoryNumber+' qty= '+myqty+ ' status= '+mystatus}); // dialog.alert({ title: 'Warning', message: 'CHECK Msg line 2 A- myInventoryNumber2='+myInventoryNumber2+' qty2= '+myqty2+ ' status2= '+mystatus2});*/ var myInventoryNumber2 = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'binnumber', line: 1 }); dialog.alert({ title: 'Warning', message: '>9'}); var myqty2 = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'quantity', line: 1 }); dialog.alert({ title: 'Warning', message: '>10'}); var mystatus2 = subrecordInvDetail.getCurrentSublistValue({ sublistId: 'inventoryassignment', fieldId: 'inventorystatus', line: 1 }); dialog.alert({ title: 'Warning', message: '>11'}); /*dialog.alert({ title: 'Warning', message: 'CHECK Msg line 2 B- myInventoryNumber2='+myInventoryNumber2+' qty2= '+myqty2+ ' status2= '+mystatus2});*/ var numLines = subrecordInvDetail.getLineCount('inventorydetail'); dialog.alert({ title: 'Warning', message: '>12'}); /* dialog.alert({ title: 'Warning', message: 'count ='+numLines });*/ var numLines = subrecordInvDetail.getLineCount('inventorydetail'); dialog.alert({ title: 'Warning', message: '>13'}); //if((myInventoryNumber == null) and (myqty > 0)) { if(!myInventoryNumber && myqty > 0) { /*dialog.alert({ title: 'Warning', message: 'IF - myInventoryNumber='+myInventoryNumber+' qty= '+myqty+ ' status= '+mystatus});*/ dialog.alert({ title: 'Warning', message: '>14 IF'}); } else if(!myInventoryNumber && !myqty) { /*dialog.alert({ title: 'Warning', message: 'Both empty, do nothing'});*/ dialog.alert({ title: 'Warning', message: '>14 ELSEIF'}); } else { /*dialog.alert({ title: 'Warning', message: 'ELSE - myInventoryNumber='+myInventoryNumber+' qty= '+myqty+ ' status= '+mystatus });*/ dialog.alert({ title: 'Warning', message: '>14 ELSE'}); } /*rec.commitLine({ sublistId: 'item' }); var recordId = rec.save();*/ dialog.alert({ title: 'Warning', message: '>15'}); } // } return { saveRecord: saveRecord } });
b
id still go with the isMandatory attempt over your code
but the primary issue you are facing is that dialog.alert is asynchronous
its also why your code is unsuitable for a saveRecord entrypoint
you need to return true to continue saving the record
returning nothing is the same as returning false
r
ahh, got it...apologies for all these questions as I am new to javascript. Thanks so much for your help 🙂