How to write the client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 10:48 PM
Hi,
I have created one variable "Total" and Multi row variable set "Bill", inside the Bill..created one "Amount" variable.
Now I need to provide the SUM of "Amount" variable into " Total" field.
How to write the onchange client script for it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2024 11:24 PM - edited 08-08-2024 11:25 PM
Catalog Client Script:
function calculateTotal() {
var totalAmount = 0;
// Get the Multi-row Variable Set data
var billData = g_form.getValue('bill'); // 'bill' is the name of the Multi-row Variable Set
if (billData) {
var billArray = JSON.parse(billData);
// Iterate through the rows and sum up the Amount values
for (var i = 0; i < billArray.length; i++) {
totalAmount += parseFloat(billArray[i].amount) || 0;
}
}
// Set the Total field with the calculated amount
g_form.setValue('total', totalAmount.toFixed(2)); // 'total' is the name of your Total field
}
// Bind the calculateTotal function to changes in the Multi-row Variable Set
g_form.onChange('bill', calculateTotal);
/ * Note :
Replace 'bill' with the actual name of your Multi-row Variable Set field.
Replace 'amount' with the actual name of the Amount variable inside the Multi-row Variable Set.
Replace 'total' with the name of the Total field where you want to display the sum. */
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 01:02 AM
Hi @Soni Tushar
Thanks for the response. Is it a onLoad or onchange script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 01:11 AM
This is onchange Catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 01:35 AM
If I select onchange, I am not able to give the MRVS, ideally it won't be coming.