- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 02:21 AM
Hello... I'm a newbie on servicenow. I want to ask how to convert currency, glide date and decimal to float so i can get result from multile them.
Contract Value = Currency
Penalty percentage = Decimal
Over due date = glide date --> i get the value from today - end date (onChange=today)
I want to get value breach penalty from multiple 3 field. i use on change = over due date. i make this script. but it not working. please help. i can't do script well. thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2017 09:16 PM
This should help.
var con = g_form.getValue('u_contract_value').substring(4);
var per = g_form.getValue('u_penalty_percentage');
var total = parseFloat(con) * parseFloat(per);
g_form.setValue('breach_penalty_amount', total);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 10:39 AM
//var con = g_form.getValue('u_contract_value'); //comment this code
alert(con); // this value is 1000 //I believe this one would be giving you like USD;1000, in that case use the below line and try,
var value = g_form.getValue('u_contract_value').substring(4);
var per = g_form.getValue('u_penalty_percentage');
alert(per); // this value is 0.1
var total = parseFloat(con) * parseFloat(per);
alert(total); // this value is NaN
alert('TEST');
g_form.setValue('breach_penalty_amount', total);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2017 09:16 PM
This should help.
var con = g_form.getValue('u_contract_value').substring(4);
var per = g_form.getValue('u_penalty_percentage');
var total = parseFloat(con) * parseFloat(per);
g_form.setValue('breach_penalty_amount', total);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 02:00 PM
Hello,
The incorrect value is not due to parseFloat. I have worked on this today and it is due to the the value you get for "g_form.getValue('u_contract_value').substring(4);" i.e., 1,000 and "," comes under octal literal which should not be used in the method parseFloat(). By having that "," in the value "1,000" system takes the integer value as "1" and gives the calculated output for "1". Hence you need to replace all the commas in the "g_form.getValue('u_contract_value').substring(4);"(which is currency field) and then parseFloat it to get the actual/correct output.
Solution is:
var date = g_form.getValue('u_over_due_date');
alert(g_form.getValue('u_contract_value'));
var value = g_form.getValue('u_contract_value');
var value1 = g_form.getValue('u_contract_value').substring(4);//You will get 1,000 from this code
var value_final =value1.replace(/,/g, "");//Replaces all commas in "value1"
var person = g_form.getValue('u_penalty_percentage');
var total = parseFloat(date) * parseFloat(value_final) * parseFloat(person);
alert(total); //Gives correct output But not NaN
Can you also mark the answer as correct and helpful to help future searches.
Regards,
Lini Aadhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2020 02:10 PM
Hello,
The incorrect value is not due to parseFloat. I have worked on this today and it is due to the the value you get for "g_form.getValue('u_contract_value').substring(4);" i.e., 1,000 and "," comes under octal literal which should not be used in the method parseFloat(). By having that "," in the value "1,000" system takes the integer value as "1" and gives the calculated output for "1". Hence you need to replace all the commas in the "g_form.getValue('u_contract_value').substring(4);"(which is currency field) and then parseFloat it to get the actual/correct output.
Solution is:
var date = g_form.getValue('u_over_due_date');
alert(g_form.getValue('u_contract_value'));
var value = g_form.getValue('u_contract_value');
var value1 = g_form.getValue('u_contract_value').substring(4);//You will get 1,000 from this code
var value_final =value1.replace(/,/g, "");//Replaces all commas in "value1"
var person = g_form.getValue('u_penalty_percentage');
var total = parseFloat(date) * parseFloat(value_final) * parseFloat(person);
alert(total); //Gives correct output But not NaN
Can you also mark the answer as correct and helpful to help future searches.
Regards,
Lini Aadhi