Currency not converted correctly (wrong Unit cost / Total cost) when creating entitlements from Entitlement Import Errors


Description

When using non-us currency, if entitlement is created directly from entitlement import, then the currency is correct on entitlement created is correct.

However if there is an Entitlement Import Error, creating entitlements from the import error will lead to wrong unit cost / total cost.

Steps to Reproduce

1. Create an excel list with Unit Cost not in US dollar. For example: CHF;20

2. Hop on an instance with SAMP activated.

3. Import entitlement from attached excel file twice, so there will be a duplicate error.

4. Click on Create Entitlement.

Workaround

This problem has been fixed. If you are able to upgrade, review the Fixed In section to determine the latest version with a permanent fix your instance can be upgraded to.

If a workaround is needed, open the Script Include SAMPEntitlementUtil, make the following change in the _createSoftwareEntitlement function :

Replace:

if (!gs.nil(row["unit_cost"])) {
var total = parseFloat(row["unit_cost"]) * parseInt(row["purchased_rights"]);
alm.setValue("unit_cost", row["unit_cost"]);
alm.setValue("cost", total);
}

With:

if (!gs.nil(row["unit_cost"])) {
if(row.isValidRecord()) { //handle cost if row is GlideRecord
var currencyCode = row.unit_cost.getCurrencyCode();
var currencyValue = row.unit_cost.getCurrencyValue();
alm.setValue("unit_cost", currencyCode + ";" + currencyValue);
}
else { //handle cost if row is a row from Excel
alm.setValue("unit_cost", row["unit_cost"]);
currencyCode = alm.unit_cost.getCurrencyCode();
}
var total = (alm.unit_cost.getCurrencyValue()) * parseInt(row["purchased_rights"]);
alm.setValue("cost", currencyCode + ";" + total);
}


NOTE: Once an out of box script is changed, it will be skipped during platform upgrade. Then you can either manually revert it to OOB after platform upgrade, or force the component to be overwritten during platform upgrade. Ref.: Overwrite customizations during an upgrade.

 


Related Problem: PRB1347830