Hunter Jacobs
11/18/2022, 8:44 PM/**
*@NApiVersion 2.1
*@NScriptType UserEventScript
*/
// Load two standard modules.
define ( ['N/record', 'N/ui/serverWidget'] ,
// Add the callback function.
function(record, serverWidget) {
// In the beforeSubmit function, add new price to Schema custom field on inv & non-inv item records.
function myBeforeSubmit(context) {
//Simplify Code - remove context.
var newRecord = context.newRecord;
var oldRecord = context.oldRecord;
//get the online price that is about to be submitted
var newItemOnlinePrice = newRecord.getSublistValue({
sublistId: "price",
fieldId: "price_1_",
line: 6
});
//get the online price that was on the record prior
var oldItemOnlinePrice = oldRecord.getSublistValue({
sublistId: "price",
fieldId: "price_1_",
line: 6
});
//If there is no change to the online price the script should be done
if (oldItemOnlinePrice === newItemOnlinePrice)
return;
//Update the custom field on the item record to match the online price. Make sure it is a number record and has 2 decimal places.
newRecord.setValue({
fieldId: 'custitem_onlineprice_for_schema',
value: `${Number(newItemOnlinePrice).toFixed(2)}`
});
}
//Return the before submit statement
return {
beforeSubmit: myBeforeSubmit
};
});
reptar
11/18/2022, 8:47 PMtoFixed(2)
does inconsistent rounding. https://gist.github.com/djD-REK/068cba3d430cf7abfddfd32a5d7903c3alien4u
11/18/2022, 8:47 PMreptar
11/18/2022, 8:48 PMalien4u
11/18/2022, 8:52 PMvar
again in 2.1.battk
11/18/2022, 8:56 PMHunter Jacobs
11/18/2022, 9:01 PMbattk
11/18/2022, 9:04 PMsterling_rose
11/18/2022, 9:34 PMHunter Jacobs
11/18/2022, 9:39 PMbattk
11/18/2022, 9:49 PMbattk
11/18/2022, 9:49 PMbattk
11/18/2022, 9:50 PMHunter Jacobs
11/23/2022, 6:16 PMHunter Jacobs
11/23/2022, 6:17 PMsterling_rose
11/23/2022, 6:18 PMbattk
11/23/2022, 6:18 PMbattk
11/23/2022, 6:19 PMHunter Jacobs
11/23/2022, 6:19 PMsterling_rose
11/23/2022, 6:20 PMsterling_rose
11/23/2022, 6:20 PMHunter Jacobs
11/23/2022, 6:20 PMHunter Jacobs
11/23/2022, 6:20 PMHunter Jacobs
11/23/2022, 6:21 PMHunter Jacobs
11/23/2022, 6:21 PMbattk
11/23/2022, 6:41 PMbattk
11/23/2022, 6:42 PMbattk
11/23/2022, 6:42 PMbattk
11/23/2022, 6:42 PM5
, the text is Online Price
Hunter Jacobs
11/23/2022, 6:53 PMHunter Jacobs
11/23/2022, 6:54 PM/**
*@NApiVersion 2.1
*@NScriptType UserEventScript
*/
// Load two standard modules.
define ( ['N/record', 'N/ui/serverWidget'] ,
// Add the callback function.
(record, serverWidget) => {
// In the beforeSubmit function, add new price to Schema custom field on inv & non-inv item records.
myBeforeSubmit = (context) => {
//Simplify Code - remove context.
const newRecord = context.newRecord;
const oldRecord = context.oldRecord;
//Pull the line value of the price level with the Id of 5 (Our Online Price Level).
const pricingSublistLineLevel = newRecord.findSublistLineWithValue({
sublistId: "price",
fieldId: 'pricelevel', //The Id of the sublist values
value: '5'
})
//get the online price that is about to be submitted
const newItemOnlinePrice = newRecord.getSublistValue({
sublistId: "price",
fieldId: "price_1_",
line: `${Number(pricingSublistLineLevel)}`
});
//get the online price that was on the record prior
const oldItemOnlinePrice = oldRecord.getSublistValue({
sublistId: "price",
fieldId: "price_1_",
line: `${Number(pricingSublistLineLevel)}`
});
//If there is no change to the online price the script should be done
if (oldItemOnlinePrice === newItemOnlinePrice)
return;
//Update the custom field on the item record to match the online price. Make sure it is a number record and has 2 decimal places.
newRecord.setValue({
fieldId: 'custitem_onlineprice_for_schema',
value: `${Number(newItemOnlinePrice).toFixed(2)}`
});
}
//Return the before submit statement
return {
beforeSubmit: myBeforeSubmit
};
});
battk
11/23/2022, 7:01 PM`${Number(pricingSublistLineLevel)}
is an unusual choice in generalbattk
11/23/2022, 7:01 PMHunter Jacobs
11/23/2022, 7:02 PMbattk
11/23/2022, 7:03 PMbattk
11/23/2022, 7:03 PMbattk
11/23/2022, 7:04 PMbattk
11/23/2022, 7:04 PMHunter Jacobs
11/23/2022, 7:04 PMline: pricingSublistLineLevel
battk
11/23/2022, 7:06 PM