Reputation: 43
I am trying to upload the below script to NetSuite in order to do a currency conversion from the purchase order currency to USD.
I would like a custom field to be updated with the USD amount whenever a user keys in any items into a purchase order.
When I upload the script, I receive the following error message:
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"MODULE_DOES_NOT_EXIST","message":"Module does not exist: N/currentRecord.js","stack":[]}**
Would greatly appreciate some guidance. Thank you.
/**
*@NApiVersion 2.x
*@NModuleScope Public
*@NScriptType UserEventScript
*/
define(['N/currency', 'N/currentRecord'],function(currency, currentRecord) {
function POCurrencyConversion() {
var Fixed_Currency = 'USD';
var Transaction_Currency = currentRecord.getValue('currency');
var Tx_currency_total = currentRecord.getValue('total');
var rate = currency.exchangeRate({
source: Transaction_Currency,
target: Fixed_Currency
});
var ConvertedAmount = Tx_currency_total * rate;
currentRecord.setValue('custbody_po_total_usd',ConvertedAmount)
}
POCurrencyConversion();
});
Upvotes: 3
Views: 3028
Reputation: 23
You cannot use "N/currentRecord" module in User Event Script. This module is supported in Client Script. instead you can make use of context.newRecord.
Upvotes: 0
Reputation: 8902
In User Events, you do not need the currentRecord
module. Rather, you can retrieve the record in context from the parameter that NetSuite passes into your event handler function:
function beforeSubmit(context) {
var Transaction_Currency = context.newRecord.getValue({fieldId: "currency"});
var Tx_currency_total = context.newRecord.getValue({fieldId: "total"});
// etc
}
Upvotes: 4