Calculate Total amount

siva118
Tera Contributor

Create a button (Total amount) whenever we click that button that button should calculate(quantity*price)

please suggest me possible ways how to achieve this. 

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

Hi @siva118 ,

I tried your problem in my PDI and it works for me, Please check the script below

 

function showTotal(){
	alert("here");
	var quan = g_form.getValue('u_quantity');
	var price = g_form.getValue('u_price');
	var total = g_form.getValue('u_total');
	alert("quan = " + quan + " price = " + price + " total = " + total );

	g_form.setValue('u_total', quan*price);

}

 

SarthakKashya2_3-1714028985209.png

 

Note: I create 3 fields on incident table - Quantity - Integer type, Price- Integer type, Total - Integer type

 

 

Result 

SarthakKashya2_0-1714028927973.png

When I click total button it shows the result 

SarthakKashya2_2-1714028958561.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

View solution in original post

Community Alums
Not applicable

Hi @siva118 ,

I had done as you say like  quantity field type is (Integer), Price field type is (currency), Total Amount field is (currency)

 

 

 

function showTotal() {
    var quan = g_form.getValue('u_quantity');
    var price = g_form.getValue('u_price_222');
    var total = g_form.getValue('u_total_222');
    alert("quan = " + quan + " price = " + price + " total = " + total);
    var intPrice = price.split(';');
    alert('intPrice = ' + intPrice[1]);
    var intTotal = total.split(';');
    var totalValue = intTotal[0] + ";" + quan * intPrice[1];
    alert('Total = ' + intTotal);
    g_form.setValue('u_total_222', totalValue);

}

 

Here is result

SarthakKashya2_0-1714040493322.png

 

 

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

View solution in original post

9 REPLIES 9

Thank you

This script only working on string type of fields but I want in currency type of fields please suggest how to achieve best way

Community Alums
Not applicable

Hi @siva118 ,

It also works for currency field please use below code 

function showTotal(){
	var quan = g_form.getValue('u_quantity');
	var price = g_form.getValue('u_price_222');
	var total = g_form.getValue('u_total');
	alert("quan = " + quan + " price = " + price + " total = " + total );
	var intPrice = price.split(';');
	alert('intPrice = ' + intPrice[1]);
	g_form.setValue('u_total', quan*intPrice[1]);

}

Result 

I created new field of type currency named Price222

SarthakKashya2_0-1714037936209.png

Now I click on UI action Total

SarthakKashya2_1-1714037984757.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

Thank you for responding 

quantity field type is (Integer)

Price field type is (currency)

Total Amount field is (currency)

Could you please do these changes and give me the result 

 

Thanks and Regards

Siva B

Community Alums
Not applicable

Hi @siva118 ,

I had done as you say like  quantity field type is (Integer), Price field type is (currency), Total Amount field is (currency)

 

 

 

function showTotal() {
    var quan = g_form.getValue('u_quantity');
    var price = g_form.getValue('u_price_222');
    var total = g_form.getValue('u_total_222');
    alert("quan = " + quan + " price = " + price + " total = " + total);
    var intPrice = price.split(';');
    alert('intPrice = ' + intPrice[1]);
    var intTotal = total.split(';');
    var totalValue = intTotal[0] + ";" + quan * intPrice[1];
    alert('Total = ' + intTotal);
    g_form.setValue('u_total_222', totalValue);

}

 

Here is result

SarthakKashya2_0-1714040493322.png

 

 

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Thank you bro 

It's working good 

 

Thanks and Regards 

Siva B