Calculate total for MRVS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 10:00 AM
I'm trying to calculate the price of a line in a MRVS. I will need to multiply the unit price and quantity and place that value into a total for that line.
I have been looking on the community for articles on how to complete this, but I have been unable to find something. I do see a lot of articles that would add the totals for each line and place that value into a field outside the MRVS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 02:56 PM
I was able to get a value calculated but setting up two catalog client scripts on the MRVS. They are both on-change scripts one for when the price field changes and another for the when the quantity changes. The script multiples the two fields and then populates the total. Below is the script and some screenshots
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var calcQty = g_form.getValue('qty');
var calcPrice = g_form.getValue('price');
var calcTotal = calcPrice * calcQty;
g_form.setValue('total', calcTotal);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2023 03:56 AM
what roles do we require to set the values in a catalog form. because my script is calculating the sum but it is not displaying in the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 07:54 PM
Hi @Casey Jones,
To calculate the multiplication of two fields, ensure that both fields only accept numerical values.
Below is the script you need to write on change of both unit price and quantity.
quantity - qty_mr; unit price - unit_price_mr.
Onchange Client Script - Validate Interger Numeric(Unit price) and Validate Interger Numeric(Quantity)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^[+]?\d*$/;
if(!regexp.test(newValue)){
alert('Please enter numeric value');
g_form.setValue('qty_mr','');
}
}
Remember to modify the script if the fields should accept the decimal values.
You have to create two onchange client scripts for calculating the total price.
Onchange Client Script - Populate Total Price(Qty)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.setValue('total_price_mr', parseFloat(g_form.getValue('unit_price_mr')) * parseFloat(newValue));
}
Onchange Client Script - Populate Total Price(Unit price)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.setValue('total_price_mr', parseFloat(g_form.getValue('qty_mr')) * parseFloat(newValue));
}
Replace parseFloat with parseInt if there are not decimal numbers.
Mark this answer as correct and helpful if it solves your issue.
Regards,
Siva Jyothi M.