I am not upload the cost values using transform msp.

Swapnil Meshram
Mega Guru

Hello Experts, 

 

I am tring to the load the data of cost using transform map in tco module, but cost value is empty. Cost field type is fx currency. 

 

Could you help in this case.

 

1 ACCEPTED SOLUTION

In field map of cost field ,use source script 

answer = (function transformEntry(source) {

    // Add your code here
    var value ="USD;"+source.u_cost;
    return value; // return the value to be put into the target field

})(source);

View solution in original post

3 REPLIES 3

Sanjay191
Tera Sage

Hello @Swapnil Meshram

You cannot directly update a currency field programmatically in ServiceNow due to some out-of-the-box (OOB) validations and business rules that are enforced on currency fields. These validations ensure consistency and accuracy, especially when currency conversions and formatting are involved.

Instead, ServiceNow manages currency field data using the fx_currency2_instance table. This table stores detailed currency-related information for each record where a currency field is used, such as the amount, currency code, and exchange rate.

So, if you're inserting or updating a record with a currency field through a script or integration, you also need to create a corresponding record in the fx_currency2_instance table. This ensures that the currency data is properly linked and rendered on the form, and that all backend processes relying on currency logic continue to function correctly.

Please refer the below script logic for this and you make changes accordingly in your transform map script as well and also you can run this background script to update the currency after uploading the data (just testing purpose)

you need two thing first is table name and second is record id that's mapped to parent_record fields. 
 

var gr = new GlideRecord('fx_currency2_instance');   
gr.addEncodedQuery('table="your table name which you are using the currency field"^parent_record="record sys_id" ')
gr.query();
if(gr.next()){
    gs.print("COMES");
    gr.amount = "8000";
    gr.currency = 'CHF';
   
    gr.update();
}

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You


In field map of cost field ,use source script 

answer = (function transformEntry(source) {

    // Add your code here
    var value ="USD;"+source.u_cost;
    return value; // return the value to be put into the target field

})(source);

MilesWeb
Kilo Contributor

This is a common challenge in ServiceNow when dealing with fx_currency fields in Transform Maps.

If you're using a script in your field map, you might be attempting to directly set the fx_currency field as a single string or number, which won't work.

You need to set the fx_currency field using a string concatenation that combines the currency code and the amount, separated by a semicolon. The format is typically currency_code;amount.