I just wanted to share with you a User Event script that I had written to add the currency
symbol to the numbers in the Totals box, found on Estimates, Bills, and Sales Orders
among others. It assumes that the current locale/currency is prefixed to the value rather
than suffixed (as in some situations) but this can be easily changed per implementation.
It doesn’t run intentionally on create or copy as the currency could be changed mid
transaction and wouldn’t reflect the value correctly. And relies on the jQuery engine
being available 1.5 seconds after the script tag (from the inline html) is executed, to be
able to load the necessary modules, extract the current currency, and inject the correct
symbol. It also expects the totalbox to have a CSS class of “totallingtable
define(["N/ui/serverWidget"], function (ui) {
var exports = {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.beforeLoad = void 0;
let clientScript = 'require( [\"N/currentRecord\", \"N/format/i18n\"], function(
CurrentRecord, Format ){' +
' try{' +
' let record = CurrentRecord.get();' +
' let x = record.getValue({ fieldId: \"currencysymbol\" });' +
' let s = Format.getCurrencyFormatter({ currency: x });' +
' $(\".totallingtable\").find(\".inputreadonly\").prepend(s.symbol);' +
' } catch (e) {' +
'
console.log( \"Cannot update currency symbols \" + e );' +
' }' +
'' +
'});';
function beforeLoad(context) {
if (context.type == context.UserEventType.CREATE || context.type ==
context.UserEventType.COPY)
return;
let insertedScript = "setTimeout(function(){ " + clientScript + " }, 1500); ";
var inline = context.form.addField({
id: 'custpage_trigger_it',
label: 'not shown',
type: ui.FieldType.INLINEHTML,
});
inline.defaultValue = "<script>" + insertedScript + "</script>";
}
exports.beforeLoad = beforeLoad;
return exports;
});