Kevin Carpenter
01/18/2022, 4:05 PMexpectedreceiptdate
field from a sublist in a Purchase Order and apply it to the linked Sales Order
items. When I try to get the Value of the date field of an item, it returns blank.
How do I define the record
module and require the format
module in the same script? Im assuming this is a formatting issue I am running into?
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
/**
* Module Description
*
* Version Date Author Remarks
* 1.00 Jan 12th, 2022 Fourth Wave Consulting
*
* Name of Script FWC-PO-Expected-Date.js
*
* Date 01/12/21
*
* Version 1.0
*
* Type UserEventScript
*
*
*
*
*
* NetSuite Ver. 2017.2 or later
*
* Script record:
* Deployment:
* Primary function: afterSubmit
*
*
* License THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* @param {String} type Context Types: scheduled, ondemand, userinterface, aborted, skipped
* @returns {Void}
*/
define(["N/record"], function (record) {
function 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 oldRec = context.oldRecord;
switch (context.type) {
case context.UserEventType.CREATE:
return;
case context.UserEventType.EDIT:
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";
}
}
}
return {
afterSubmit: afterSubmit,
};
});
Sandii
01/18/2022, 4:13 PMSandii
01/18/2022, 4:14 PMdefine(['N/record', 'N/format'], function (record, format)
Kevin Carpenter
01/19/2022, 4:51 AMrequire
instead, but when I change it to require it fails.Kevin Carpenter
01/19/2022, 4:52 AMKevin Carpenter
01/19/2022, 4:53 AMKevin Carpenter
01/19/2022, 5:03 AMSean Murphy
01/20/2022, 11:50 AMfor (var index = 0; index < itemLength; index++) {
var item = {};
var line_expectedreceiptdate = oldRec.getSublistValue({
sublistId: "item",
fieldId: "expectedreceiptdate",
line: index,
});
Kevin Carpenter
01/21/2022, 6:39 AMSean Murphy
01/25/2022, 2:33 PM