We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to convert and multiply currency, glide date, and decimal?

zulhiyatiuwi
Tera Expert

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)

find_real_file.png

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.

find_real_file.png

1 ACCEPTED SOLUTION

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);


View solution in original post

13 REPLIES 13

Hello...



I still got NaN value when i try this script.


I cant get the right value when i try to convert it. when i convert decimal (0,1) using parseFloat, the result become 1. -,-"


there should be decimal not comma in u_penalty_percentage field.



can you please change this line


var value = g_form.getValue('u_contract_value');



to


var value = g_form.getValue('u_contract_value').replace(",", ".");


Hello...


I use comma because when i used (.), 0 disappear. 0.1 --> become 1. The value still NaN. I still cant get the right value...


that shouldn't be case for Decimal field type, it save the value like 0.5. I have tested on Istanbul instance and the calculation works fine. What version of serview-now are you using?



find_real_file.png


Hello...



I'm using istanbul too.


But i create new personal istanbul instance to try the script. and the script still cant working properly. this is my script. i create client script onload to test it.



var con = g_form.getValue('u_contract_value');


alert(con); // this value is 1000


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);




Thank you


find_real_file.png