Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @NApiVersion 2.x
- * @NScriptType UserEventScript
- */
- define([
- 'N/log'
- ], function(
- log
- ) {
- const exports = {};
- function afterSubmit(context) {
- var newRecord = context.newRecord
- switch (context.type) {
- case context.UserEventType.CREATE:
- return ;
- case context.UserEventType.EDIT:
- var payload = getSalesOrderItems(newRecord);
- log.debug(payload);
- break;
- default:
- throw 'Invalid event type';
- }
- }
- exports.afterSubmit = afterSubmit;
- return exports;
- });
- function getSalesOrderItems(salesRecord)
- {
- var items = [];
- var itemLength = salesRecord.getLineCount({
- sublistId : 'item'
- });
- if (itemLength === 0) throw 'Order does not have any valid item';
- for (var index = 0; index < itemLength; index++) {
- var item = {};
- var itemId = salesRecord.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.sku = itemRecord.getValue('itemidorig');
- item.quantity_committed = salesRecord.getSublistValue({
- sublistId: 'item', fieldId: 'quantitycommitted', line: index
- });
- item.quantity = salesRecord.getSublistValue({
- sublistId: 'item', fieldId: 'quantity', line: index
- });
- items.push(item)
- return items;
- }
- }
- {
- [{
- "sku":"EMOST00405",
- "quantity":2
- }]
- }
- {
- [{
- "sku":"EMOST00405",
- "quantity_committed": 1,
- "quantity":2
- }]
- }
Add Comment
Please, Sign In to add comment