how can i calculate two currency fields?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 02:23 AM
i need to calculate two currency fields.
field name: u_currency1 (type currency)
field two name: u_currency2 (type currency)
field 3 name: u_store : (type choice )
my req is
u_currency1 / u_currency2 *100 basced on this value set the choice field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 02:37 AM
Hi, Sachin
You may create 2 Client Scripts onChange of "u_currency1" and "u_currency2" fields to react on changes of these currency fields.
And to set field3 value - use in each Client Script g_form.setValue('u_store','field3NewValue') to set your result.
For Example:
assuming you new value for 'u_store' should be Label:"Macy's King of Prussia" value:'macy_kp':
then you onChange Script whould look like:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var cur1 = parseInt(g_form.getValue('u_currency_1'));
var cur2 = parseInt(g_form.getValue('u_currency_2'));
var result = cur1/cur2*100;
if (result > 50) {
g_form.setValue('u_store','macy_kp');
}
}
}
however, you may need to use GlideAjax to do proper calculations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 03:00 AM
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var currency1 = g_form.getValue('u_currency1');
var currency2 = g_form.getValue('u_currency2');
var ga = new GlideAjax('SetCurrency');
ga.addParam('sysparm_name', SetCurrencyFunc);
ga.addParam('sysparm_currency1', newValue);
ga.addParam('sysparm_currency2', currency2);
ga.getXML(set_u_store);
}
function set_u_store(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_store', answer);
return answer;
}
Script Include(Client-callable):
var SetCurrency = Class.create();
SetCurrency.prototype = Object.extendsObject(AbstractAjaxProcessor,{
SetCurrencyFunc:function(){
var result = '';
/*
currency calculation according following documentation and set result variable
https://docs.servicenow.com/bundle/jakarta-platform-administration/page/administer/currency/concept/currency-values-scripts.html
*/
return result;
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 02:41 AM
Hi
Please write a client script to accomplish this.
Please find below the Client Script.
function onLoad()
{
var price3=0;
var price1=parseInt(g_form.getValue('u_currency_1'));
var price2=parseInt(g_form.getValue('u_currency_2'));
price3 = price1 / price2 * 100;
g_form.addOption('your_choice_field_name',price3,'label')
}
Mark Correct if it helps.
Warm Regards,
Omkar Mone
www.dxsherpa.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 02:42 AM
price3 is Choice List - not currency type