String to Price field mapping

RohitGeorgV
Mega Guru

From external system to transform table I'm receiving the amount as- 100 EUR which I'm mapping it to a table which has the field 'u_amount' which is of type price. I have written a script for the transform but only the value(100) is getting populated. What I am expecting is it is EUR then the currency type should be â‚¬.

 

RohitGeorgV_0-1756904559022.png

 

answer = (function transformEntry(source) {

    if (source.u_price) {
        var parts = source.u_price.split(' ');
        if (parts.length === 2) {
            var amount = parseFloat(parts[0]);
            var currency = parts[1].toUpperCase();
            target.u_currency1.setValue(amount,currency);
        }
    }

})(source);

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@RohitGeorgV 

you should set currency as well

Don't use field map, please use onBefore transform script for this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    var parts = source.u_price.split(' ');
    if (parts.length === 2) {
        var amount = parseFloat(parts[0]);
        var currency = parts[1].toUpperCase();
        target.u_currency1.setValue(currency + ";" + amount);
    }

})(source, map, log, target);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@RohitGeorgV 

you should set currency as well

Don't use field map, please use onBefore transform script for this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    var parts = source.u_price.split(' ');
    if (parts.length === 2) {
        var amount = parseFloat(parts[0]);
        var currency = parts[1].toUpperCase();
        target.u_currency1.setValue(currency + ";" + amount);
    }

})(source, map, log, target);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader