Populating a currency field (through scripting) with a value based on another currency field using getDisplayValue() populates the field with 0.00
In Helsinki, when a currency field is updated through a script with the getDisplayValue of another currency field (so including the currency symbol in the string value, e.g., current.sysapproval.price.getDisplayValue();), the code accepts that and is able to strip off the currency symbol and populate the field with just the numeral part. In Istanbul and later, the same update does not work; the currency field is not updated or gets set to 0.00 if it had no value before.
The following case reproduces the behavior that was reported.
The table u_test_table has 2 similar currency fields:
The money field currently has the value 711.09 for the record with sys_id 29ee07db131cf200bc5bb9d12244b0b5.
Run the following background script:
var gr = new GlideRecord("u_test_table");
gs.debug(' amount: '+ gr.money);
gr.u_amount3 = gr.money.getDisplayValue();
// gr.u_amount3 = gr.money;
gs.debug(' u_amount3: '+ gr.u_amount3);
--> that does not change the value for u_amount3
Change the script so that it does not update the value with getDisplayValue but rather just with the gr.money value.
It then works and updates the value.
Doing the same on a Helsinki instance, even with the provided code (with gr.money.getDisplayValue()), updates the u_amount3 field to the expected value 711.09.
The getDisplayValue() function returns the value of the currency field, formatted in standard currency formatting (with decimal and thousand separator) including the currency symbol. In Helsinki, that currency symbol get stripped of the value when populating a field with this value. In versions beginning with Istanbul, this behavior no longer happens.
In the script, do not use getDisplayValue() from a currency field to populate another currency field. Use, for example, current.price, or gr.money as in the example. From a coding perspective, there is no valid reason to populate a currency value with the display value of another currency field.
For more information, see the product documentation topic Currency values in scripts.