Currency in Record Producer

salvadormarchan
Kilo Guru

Hi All,

 

To my surprise, I don't see any 'currency' (or equivalent) data type in the record producer's variable. So, I created two fields - one for the currency ("Old Currency" variable - datatype: Select Box; with dropdown values of world currencies) and one for the current value ("Old Price" variable - datatype: Single Line Text; with a client script that evaluates 2-decimal places numeric values).

In the target table, I have a field which can hold a currency   ("Old Price" field - datatype: Currency).

 

Question: How do I map "Old Currency" variable and "Old Price" variable into "Old Price" field?


In the record producer, there is a "Script" field and I may do server-side scripting. I can use "current"   to set values for the target table and I can use "producer" object to retrieve the "Old Currency" variable's value. I tried using a Glide Record to force the currency but no luck.

===========================================================

Here's my script so far:

var myOldCurrt = producer.oldCurrency.toString();

gs.log(current.sys_id,'MCS 1');

var old = new GlideRecord('fx_currency_instance');

old.addQuery('id', current.sys_id.toString());

old.addQuery('field', 'u_old_price');

old.query();

gs.log(old.getRowCount(),'MCS 2');

if(old.next()) {

    old.currency = myOldCurrt;

    old.update();

}

//var myNewCurrt = producer.newCurrency.toString();

===========================================================

I appreciate it for any tips or leads.

Thanks,

Dor

5 REPLIES 5

Michael Fry1
Kilo Patron

Right, you can use current and producer to get your results:



current.old_price = producer.old_price;


The amount is transferred but not the currency.


Jared Healy2
Kilo Expert

Hey Dor,



I'm not sure if you've got this figured out yet but the wiki has some good information on scripting currency fields linked below. The issue is that a currency field assumes the currency of the current users session unless specified in the format (<currency field> = "USD;<amount>"). So, in you're case you'd need to do something like the below:



// field_name = "<currency>;<amount>";


// Example to set with USD


current.old_price = "USD;" + producer.old_price;



// The interpreted output should be


current.old_price = "USD;200.99";



Scripting Currency and Price Fields



I hope that helps,


Jared Healy


This is the right answer!!!!! Thank you........