Add Functions for Currency and Date Formatting
Start by adding functions for formatting date and currency according to the preferences of the person using the app.
- In the App UIs pane, click <yourguid>-orders. For example, akhan-orders.
- On the <yourguid>-orders tab, click the
JavaScript subtab.Caution: Make sure you select the JavaScript subtab for the App UI and not the manage-orders page. The code snippet needs to be added to the App UI JavaScript file (and not the manage-order page JavaScript).
- In the JavaScript subtab, delete the entire code block, so that the JavaScript page is empty.
- Copy and paste this custom function that uses utility classes to format date and
currency values into the JavaScript page.
define([ 'ojs/ojconverterutils-i18n', 'ojs/ojconverter-number', 'ojs/ojconverter-datetime', 'oj-sp/common-util/common-util' ], function ( IntlConverterUtils, NumberConverter, DateTimeConverter, utilityClass) { 'use strict'; var AppModule = function AppModule() { // get the default date format pattern from user profile var dateOptions = { formatStyle: "date", pattern: utilityClass.getDateFormatPattern() }; // create just one instance of converter per application this.dateConverter = new DateTimeConverter.IntlDateTimeConverter( dateOptions ); // create map to cache currency converters this.currencyConverterMap = new Map(); }; AppModule.prototype.formatDate = function (date) { return this.dateConverter.format(date); }; AppModule.prototype.formatCurrency = function (currCode, value) { // if caller provides the currency code then use it otherwise get the default one from the user profile currCode = currCode ? currCode : utilityClass.getCurrencyCode(); // if converter doesn't exists in map create a new one and update cache if (!this.currencyConverterMap.get(currCode)) { var numberOptions = { style: "currency", currency: currCode }; // update the cache with new converter this.currencyConverterMap.set(currCode, new NumberConverter.IntlNumberConverter(numberOptions)); } return this.currencyConverterMap.get(currCode).format(value || 0); }; return AppModule; });
The code you entered should look like this: - Close the <yourguid>-orders tab.