Kevin Carpenter
01/16/2022, 1:55 PM{expectedreceiptdate}
for all items and put into array
2. Open ‘created from’ sales order and update the ‘expected ship date’ column field with ID: {expectedshipdate}
for each item to match the value from the PO.
However I cannot get anything to show up in the console. I have also tried to log this value to no avail. It does run correctly but all I see in the Execution Log is “Start Script”.
What am I doing wrong?NickSuite
01/16/2022, 7:57 PMNickSuite
01/16/2022, 7:57 PMKevin Carpenter
01/18/2022, 1:24 PMfunction
_afterSubmit_(context) {
_log_._debug_('Start Script ');
// - get the value of {expectedreceiptdate} for all items and put into array
`// - If no items have expectedreceiptdate
- end script`
// - Open 'created from' sales order and update the 'expected ship date' coulmn field with ID: {expectedshipdate} for each item to match the value from the PO.
_if_ (_context_._type_
!==
_context_._UserEventType_._CREATE_
&&
_context_._type_
!==
_context_._UserEventType_._DELETE_ ) {
_return_;
}
// Get number of Item lines from Purchase Order Record
_var_ CurrentRecord _= context.currentRecord_;
_var_ numLines _= CurrentRecord.getLineCount({_"sublistId"_:_ "item"_})_;
_log_._debug_('Lines: ', numLines);
}Kevin Carpenter
01/18/2022, 1:24 PMNickSuite
01/18/2022, 6:33 PM_var_ CurrentRecord _= context.currentRecord_;
NickSuite
01/18/2022, 6:33 PMNickSuite
01/18/2022, 6:33 PMNickSuite
01/18/2022, 6:34 PMNickSuite
01/18/2022, 6:34 PMNickSuite
01/18/2022, 6:34 PMKevin Carpenter
01/19/2022, 5:10 AMfunction afterSubmit(context) {
// - get the value of {expectedreceiptdate} for all items and put into array
// - If no items have `expectedreceiptdate` - end script
// - Open 'created from' sales order and update the 'expected ship date' coulmn field with ID: {expectedshipdate} for each item to match the value from the PO.
if (context.type == context.UserEventType.EDIT) {
// var objRecord = record.load({
// type: record.Type.PURCHASE_ORDER,
// id: context.newRecord.getValue({fieldId: 'transaction'}),
// isDynamic: true
// });
var oldRec = context.oldRecord;
switch (context.type) {
case context.UserEventType.CREATE:
return;
case context.UserEventType.EDIT:
// var payload = getSalesOrderItems(newRecord);
// log.debug(payload);
// var newRecord = context.newRecord
// Get number of Item lines from Purchase Order Record
//var CurrentRecord = JSON.stringify(context.currentRecord);
var itemLength = oldRec.getLineCount({ sublistId: "item" });
log.debug({
title: "Num Lines: ",
details: itemLength,
});
var items = [];
if (itemLength === 0) throw "Order does not have any valid item";
for (var index = 0; index < itemLength; index++) {
var item = {};
var itemId = oldRec.getSublistValue({
sublistId: "item",
fieldId: "item",
line: index,
});
try {
var itemRecord = record.load({
type: record.Type.SERIALIZED_INVENTORY_ITEM,
id: itemId,
});
} catch (ex) {
if (JSON.parse(ex).name == "SSS_RECORD_TYPE_MISMATCH") {
itemRecord = record.load({
type: record.Type.KIT_ITEM,
id: itemId,
});
}
}
}
if (!itemRecord) throw ('Item with id ' + itemId + ' does not exist');
item.expectedreceiptdate = itemRecord.getValue('expectedreceiptdate');
log.debug({
title: "Expected Receipt: ",
details: item.expectedreceiptdate,
});
break;
default:
throw "Invalid event type";
}
}
Kevin Carpenter
01/19/2022, 5:11 AMNickSuite
01/19/2022, 6:15 AMNickSuite
01/19/2022, 6:16 AMKevin Carpenter
01/19/2022, 10:40 AMKevin Carpenter
01/19/2022, 10:41 AM