Fetch currencies using Suite Script 2.0
Things I want to do:
- I want to add currencies in Financial subtab when new customer / client gets created based on its Primary currencies.
- How should i fetch the currencies which are actually stored in NetSuite ->List->Accounting-> Currencies.
- And base on that currencies I need to append rest of the currencies excluding the default to customer record.
function beforeSubmit(context) {
var tgType = context.type;
if(tgType == ‘create’) {
var rec = context.newRecord;
log.debug({title: ‘Record Type ‘, details: context.newRecord.type });
const currencies = [‘CAD’,’EUR’,’USD’,’GBP’];
// var currencies = [3,4,2,1];
var cur = rec.getValue({
fieldId: ‘currency’,
});
log.debug(“Currency:”,cur);
var custCurrencyLines = rec.getLineCount({
sublistId: “currency”
});
var cnt = 0;
for (var key in currencies) {
if (currencies[key] && cnt <=2) {
rec.insertLine({
sublistId: “currency”,
line: cnt
});
log.debug(“Count is”,cnt);
rec.setSublistText({
sublistId: “currency”,
fieldId: “currency”,
line: cnt,
text: currencies[key]
});
cnt++;
}
}
}
}
return {
beforeSubmit: beforeSubmit
};
I want to fetch the currencies from NetSuite using suite script 2.0.
Hi,
You can search for currencies using the N/search module.
search.create({ type: search.Type.CURRENCY, columns: ['internalid', 'name', 'symbol'] });
Thanks,
Chris