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

Deepak Shaerma
Kilo Sage

Hi @siva118 
Navigate to System UI -> UI Actions. 
Apply on form header

function calculateTotal() {
    // Get the current record
    var currentRecord = g_form.getUniqueValue();
    
    // Assuming 'quantity' and 'price' are the field names
    var quantity = parseFloat(g_form.getValue('quantity'));
    var price = parseFloat(g_form.getValue('price'));
    
    // Calculate total
    var total = quantity * price;
    
    // Set the total amount field
    g_form.setValue('total_amount', total.toFixed(2)); // Adjust field name accordingly
}

if (typeof window == 'undefined') {
    calculateTotal();
}

Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma 


I have try this but it's not working

Hi @siva118 

try to remove if condition The check if (typeof window == 'undefined')

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