Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business Rule to take string or integer and * and populate total in another field

deneech
Giga Expert

Hello Everyone.

I am trying to create a business Rule to take the number from u_number_of_standard_server_software (right now I have this field as a string, I can change to integer if that will help).

Multiply   it by 6,439

Get the answer and populate it in u_standard_server_software_annual (read-only Currency field)

Here is my code

new num.JPG

Thanks for all your help. I will make sure i mark your advice as helpful or correct if you can help me solve this problem.

Denee

1 ACCEPTED SOLUTION

In your business rule, you can try like this,



var value = parseInt(current.u_number_of_standard_server_software)* 6349;


current.u_standard_server_software_annual_amount = current.u_standard_server_software_annual_amount + ';' + value;



But i believe this can easily be done through onChange() client script on u_number_of_standard_server_software field to get the calculation done, like



var val = (parseInt(newValue) * 6349);


g_form.setValue('u_standard_server_software_annual_amount', val);    



Let's see if this helps.


View solution in original post

10 REPLIES 10

sishir,



Actuallu i am neew to this community .



If I want to send a mail to any of the member or personal chat , how would i do that.


Hello Shishir



I think it could be a problem with my condition because when i save the form it doesn't populate the total. Any thoughts.not working.JPG



thanks


Denee


Hi Denee,



I tried in my demo instance and it working fine.


Using Business rule:


find_real_file.png



Using Client Script:


find_real_file.png



Result looks like this:


find_real_file.png


Thanks Kunal



I figured it out.



Denee


(function executeRule(current, previous /*null when async*/) {

var mil=current.u_string_1.getDisplayValue();
var math=current.u_string_3.getDisplayValue();
var eng=current.u_string_4.getDisplayValue();
var sci=current.u_science.getDisplayValue();
gs.addInfoMessage("Calculate wil start here");
current.u_string_5=parseInt(mil+math+eng);
gs.addInfoMessage("Record will sbmit now");
//current.u_string_5=current.total;
gs.addInfoMessage("Record will sbmit now:" +'u_string_5');

 

i wrote this business rule to add 4 field and popupate the value on 5th field, but the problem is i'm able to multiply but unable to add , by adding with (+) , it adding as a string, ex-10+20=1020.

how can i declare this as an integer, kindly help me out