Adding a Custom Transaction Body Field to Capture the Foreign Exchange Rate on an Invoice:
1. Create a Custom Field:
– First, create a custom field (e.g., `custbody6`, which is the internal ID of the custom field).
2. Display Field:
– Ensure that the field is displayed in the ‘CUSTOM’ tab.
3. Create a User Event Script:
– Use the following script to populate the foreign exchange rate:
function userEventBeforeLoad(type, form, request) {
var currency = nlapiGetFieldValue(‘currency’);
var transactionDate = nlapiGetFieldValue(‘trandate’);
var conversionFactor = nlapiExchangeRate(currency, ‘USD’, transactionDate);
nlapiSetFieldValue(‘custbody6’, conversionFactor, true, true);
}
4. Upload the Script:
– Navigate to Customization > Scripting > Scripts > New and upload the script file.
5. Script Configuration:
– Once uploaded, select User Event as the script type.
6. Configure the Script:
Scripts Tab:
– Name: (e.g., Exchange Rate Script)
– Before Load Function: `userEventBeforeLoad`
Deployments Tab:
– Applies To: Invoice
– Status: Testing (for testing purposes) or Released(for production).
– Log Level: Debug
7. Save:
– After configuring the settings, click Save.