Jira Code: APC-20
Create a custom field in work order record to save the total picked quantity.
The proposed solution will calculate the total quantity of picked items for a work order and save it in the new field.
WorkFlow Action Script: APC-20 JJ WA Qty Pickup
/**
* @NApiVersion 2.x
* @NScriptType workflowactionscript
*/
/*******************************************************************************
* CLIENTNAME:Allied Power & Control
* APC-20
* Calculate the total quantity of picked items in work order and display it in a custom field of work order.
* **************************************************************************
* Date : 01-05-2019
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script to set the field 'Total Quantity Picked' in the WOs based on the total
* quantity picked.
* Date created : 01-05-2019
*
* REVISION HISTORY
*
* Revision 1.0 ${01-05-2019} nd : created
*
******************************************************************************/
define(['N/search','N/record'],
function(search,record) {
/**
* 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) {
log.debug('test','test');
var type;
var rf_pickup_line = scriptContext.newRecord.id
log.debug('rf_pickup_line',rf_pickup_line)
var fieldLookUp = search.lookupFields({
type: 'customrecord_rfs_pick_state_line',
id: rf_pickup_line,
columns: ['custrecord_rfs_ps_line_pick_state']
});
var rf_smart_pickupState = fieldLookUp.custrecord_rfs_ps_line_pick_state[0].value;
log.debug('rf_smart_pickupState',rf_smart_pickupState)
var fieldLookUp2 = search.lookupFields({
type: 'customrecord_rfs_pick_state',
id: rf_smart_pickupState,
columns: ['custrecord_rfs_pick_state_transaction']
});
var work_orderNo = fieldLookUp2.custrecord_rfs_pick_state_transaction[0].value;
log.debug('work_orderNo',work_orderNo)
var transactionSearchObj = search.create({
type: "transaction",
filters:
[
["internalidnumber","equalto",work_orderNo],
"AND",
["mainline","is","T"]
],
columns:
[
search.createColumn({name: "type", label: "Type"})
]
});
var searchResult1 = transactionSearchObj.run().getRange({
start: 0,
end: 1
});
for (var i = 0; i<searchResult1.length; i++) {
type = searchResult1[i].getValue({
name: "type"
});
}
log.debug('type',type)
if(type == 'WorkOrd'){
var customrecord_rfs_pick_stateSearchObj = search.create({
type: "customrecord_rfs_pick_state",
filters:
[
["custrecord_rfs_pick_state_transaction","anyof",work_orderNo]
],
columns:
[
search.createColumn({
name: "custrecord_rfs_pick_state_status",
summary: "MAX",
label: "Status"
}),
search.createColumn({
name: "custrecord_rfs_pick_state_transaction",
summary: "MAX",
sort: search.Sort.ASC,
label: "Order Number"
}),
search.createColumn({
name: "custrecord_rfs_pick_state_user",
summary: "MAX",
label: "User"
}),
search.createColumn({
name: "custrecord_rfs_ps_line_quantity",
join: "CUSTRECORD_RFS_PS_LINE_PICK_STATE",
summary: "SUM",
label: "Quantity"
}),
search.createColumn({
name: "custrecord_rfs_ps_line_item",
join: "CUSTRECORD_RFS_PS_LINE_PICK_STATE",
summary: "MAX",
label: "Item"
})
]
});
var searchResult = customrecord_rfs_pick_stateSearchObj.run().getRange({
start: 0,
end: 100
});
log.debug('searchResult.length',searchResult.length);
log.debug('searchResult',searchResult);
for (var j = 0; j<searchResult.length; j++) {
var qty = searchResult[j].getValue({
name: "custrecord_rfs_ps_line_quantity",
join: "CUSTRECORD_RFS_PS_LINE_PICK_STATE",
summary: "SUM",
label: "Quantity"
});
}
log.debug('qty',qty);
var otherId = record.submitFields({
type: record.Type.WORK_ORDER,
id: work_orderNo,
values: {
custbody_jj_total_picked_qty: qty
}
});
}
// return qty;
}
return {
onAction : onAction
};
});