Calculating values of field automatically

SAM321
Tera Contributor

Hi all, so i have 4 fields in form like,

Unit price - 5000

Quantity - 6

discount - 10%

when i fill this fields 

Total price field should be filled automatically...How to achieve this

1 ACCEPTED SOLUTION

@SAM321 you should right click on unit in your form and see the field name and that names of other fields respectively should be changed in the script in order to make it work.

View solution in original post

9 REPLIES 9

Tony Chatfield1
Kilo Patron

Hi, exactly how depends on if this value needs to be visible to the end user before the form is saved? If yes then you would want a client script for each of the 3 contributing fields that recalculates the total when the field is changed.
If the total does not need to be set on the form, then you can use a before insert\update BR triggering when one of the 3 fields changes

aditya174
Tera Guru

Hi @SAM321 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var Up = g_form.getValue('u_unitprice');
    var units = g_form.getValue('u_units');
    var dis = g_form.getValue('u_discount') / 100;

    var tot = Up * units * dis;
    g_form.setValue('u_total',tot);
    //Type appropriate comment here, and begin script below

}

try this piece of code and please mark my answer as helpful if it helps you in any way.

Regards, 

Aditya

SAM321
Tera Contributor

@Tony Chatfield1  yes, i need script for , whenever any of the above field get changes , The total Field should get value automatically.

Hi @SAM321 , try the script by changing the getvalue parameters with your field's name for the same and it should work.

Do mark my ans helpful.

 

Regards,

Aditya