Jira Code: AD 10
We have to set use bin field true on item record when location’s use bin is true. When the location’s use bin is false, the user can set use bin true/ false.
Workflow action script
/**
* @NApiVersion 2.x
* @NScriptType workflowactionscript
* @ScriptTitle AD 10 WA To set Use Bin ticked
* @ScriptID customscript_ad10_wa_set_use_bin_ip
* @RelatedTask AD 10
* @Description :It is to Workflow action to set "Use Bins" on Item Record if Location "use bins" = True
* @CreatedBy AJ 28/12/2018
*/
define(['N/record', 'N/search'],
/**
* @param {record} record
* @param {search} search
*/
function(record, search) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @Since 2016.1
*/
function onAction(scriptContext) {
try{
// to get the current record(Item)
var itemRecord = scriptContext.newRecord;
// to get the current record(Item)
var itemRecordId = scriptContext.newRecord.id;
// to get the current record(Item)type
var itemRecordType = scriptContext.newRecord.type;
// to get the default location
var defLoc = itemRecord.getValue({
fieldId:'preferredlocation'
});
var defLocTxt = itemRecord.getText({
fieldId:'preferredlocation'
});
// to go to location record
//location
if(defLoc)
{
var locationSearchObj = search.create({
type: "location",
filters:
[
["internalidnumber","equalto",defLoc]
],
columns:
[
search.createColumn({
name: "name",
sort: search.Sort.ASC,
label: "Name"
}),
search.createColumn({name: "usesbins", label: "Use Bins"})
]
});
var searchResultCount = locationSearchObj.runPaged().count;
var searchResult = locationSearchObj.run().getRange({
start:0,
end:1
});
// to get the values
if(searchResultCount>0)
{
var useBin = searchResult[0].getValue({name: "usesbins", label: "Use Bins"});
if(useBin==true)
{
itemRecord.setValue({
fieldId:'usebins',
value:true
});
}
else if(useBin==false)
{
itemRecord.setValue({
fieldId:'usebins',
value:false
});
}
}
}
}catch(e)
{
log.debug("Err@ FN onAction ",e.message);
log.error("Err@ FN onAction ",e.message);
}
}
return {
onAction : onAction
};
});