Calculation script

Sharath807
Tera Contributor

Hi all, so i need to calculate the percentage value in respective fields.

Screenshot (187).png

left side values will be filled manually.. right side it should populate autocalculation .cgst and sgst will be half % of GST that is it should show in amount . CGST : 180 , SGST : 180 ., IGST : 0  .    If we clear values in CGST and SGST . then IGST should show total of CGST and SGST that is 360.  can i get script for it

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi,

 

You can use a Client Script defined for the table where your screenshot comes, and field name of "GST%".  And use similar logic as in my example:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var ua = g_form.getDecimalValue('u_amount');
	var ud = g_form.getDecimalValue('u_discount');

	var adjustment = (ua * (ud/100));
	var total = (ua) - (adjustment);
//	g_form.addInfoMessage("adjustment = " + adjustment + ", total type = " + typeof total);
	g_form.addInfoMessage("ua=" + ua + ", ud=" + ud + ", total=" + total.toFixed(2));
	g_form.setValue('u_grand_total', total.toFixed(2));
}

 

Also, review existing client scripts in your instance for other examples. And use https://docs.servicenow.com/ for related documentation, and google for javascript syntax/usage.

View solution in original post

1 REPLY 1

Bert_c1
Kilo Patron

Hi,

 

You can use a Client Script defined for the table where your screenshot comes, and field name of "GST%".  And use similar logic as in my example:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var ua = g_form.getDecimalValue('u_amount');
	var ud = g_form.getDecimalValue('u_discount');

	var adjustment = (ua * (ud/100));
	var total = (ua) - (adjustment);
//	g_form.addInfoMessage("adjustment = " + adjustment + ", total type = " + typeof total);
	g_form.addInfoMessage("ua=" + ua + ", ud=" + ud + ", total=" + total.toFixed(2));
	g_form.setValue('u_grand_total', total.toFixed(2));
}

 

Also, review existing client scripts in your instance for other examples. And use https://docs.servicenow.com/ for related documentation, and google for javascript syntax/usage.