Need to multiply 2 fields on portal

Sri56
Tera Contributor

Hi Team,

 

we have two fields :

number of request (single line text) and capacity (single line text).

we need to multiply these and set in capacity only once.

trying the below code

but this is running on a loop.

 

 

please help me with the code.
var res = parseInt(g_form.getValue('number_of_requests')) * parseInt(newValue);
        alert(res);
        g_form.setValue('capacity', res);

So when number of request given 40 and capacity given 3 when user take off the cursor it should multiply and set as 120.

the above code should not trigger again (whereas not in a loop)

Please help!

Sri56_0-1699855719929.png

 

Thanks!

Sri

10 REPLIES 10

Just to understand, the calculation works but you get alert multiple times is what you mean? If so, how many times you get the alert.

Hi Jaspal,

 

Many Times.

please find the screenshot

Sri56_0-1699863432447.png

 

its multiplying nth time.

basically it should execute once.

 

please help!

 

Thanks,

Sri

These are not the alerts you have added to the script but more of error messages. Is the widget modified? also, please check all relevant client scripts that run on the load of the form or so.

Hi Jaspal,

There is a alert message poping up by multiplying the values.

If we keep on clicking ok, then getting the above error message.

 

Please help!

 

Thanks,

Sri

Anand Kumar P
Giga Patron
Giga Patron

Hi @Sri56 ,

You can use below script to check if the calculated value is different from the current value

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var numberOfRequests = parseInt(g_form.getValue('u_request'));
var capacity = parseInt(g_form.getValue('u_capicity'));
var res = numberOfRequests * capacity;
var currentCapacity = g_form.getValue('capacity');
// Check if the calculated value is different from the current value
if (res !== currentCapacity) {
    g_form.setValue('capacity', res);
    alert(res);
}
}

 

 

Please mark it solution proposed and helpful if its serves your purpose.

Thanks,

Anand