Change field value ofter submitting

Rosy14
Tera Guru

Hi,

I have a float type field A. I want to set the value by A's value/100 when submit. below code is not working in portal.

function onSubmit() {
   //Type appropriate comment here, and begin script below
   var x = g_form.getValue("u_duty_percentage");
   x = x/100;
   //g_form.addInfoMessage(x);
   g_form.setValue("u_duty_percentage",x);
}
 
Rosy14_0-1720190623874.png

 

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi Rosy,

 

Is this working in next experience /  native view?

Change the UI Type field to ALL

 

Try the script below

 

var value = parseFloat(g_form.getValue('u_duty_percentage')/100);
g_form.setValue('u_duty_percentage', value.toFixed(2));

 

 

Curious, why don't you use this in on change client script?

 

-Anurag

View solution in original post

4 REPLIES 4

Yashsvi
Kilo Sage

Hi @Rosy14,

please check below script:

function onSubmit() {
   var x = g_form.getValue("u_duty_percentage");
   if (x) { // Ensure x is not null or empty
       x = parseFloat(x) / 100; // Convert to float and divide by 100
       g_form.setValue("u_duty_percentage", x);
   }
   return true; // Ensure form submission continues
}

Thank you, please make helpful if you accept the solution. 

Anurag Tripathi
Mega Patron
Mega Patron

Hi Rosy,

 

Is this working in next experience /  native view?

Change the UI Type field to ALL

 

Try the script below

 

var value = parseFloat(g_form.getValue('u_duty_percentage')/100);
g_form.setValue('u_duty_percentage', value.toFixed(2));

 

 

Curious, why don't you use this in on change client script?

 

-Anurag

If I use onchang its giving stack overflow error

How about a BR instead then?

on submit client script would make sense if it was a catalog, for a general record I'm not too sure.

-Anurag