- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 11:09 AM
I’m facing an issue with auto displaying the subtotal field in the procurement catalog item,
I’m taking the items, quantity and estimated total in multirow variable set and I want to display the cost of all items in the subtotal field in the single row variable set.
In the first attachment the subtotal field is not changing when there is a change in multirow variable set.
But when I put some value in the subtotal field it is automatically overridden, and the actual value pops up
This is the on-change script I’m using on the subtotal field.
Please let me know if anyone has ever faced this kind of issue or if there is any solution to solve this issue.
Thanks,
Tarun
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:47 PM
Hi @TarunChowdary ,
This is how I was able to achieve this, it is kinda workaround but should work fine in your case:
This is my sample form:
1. I have added a checkbox to calculate the total, since we dont have an event to determine the addition or deletion of records in the mrvs.
2. I run a client script when the calculate total button is true and make the mrvs readonly. Making it read only is important coz if it is not read only, users can add new records/delete records and we wont get the event(refer pt 1).
3. If they have to enter new record, then they have to uncheck the calculate total checkbox.
Client script on Catalog item:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var calTotal = g_form.getValue('calculate_total'); //calculate total is the checkbox
if (calTotal == 'true') {
var multiRowVariableSet = JSON.parse(g_form.getValue('item_list')); //mymrvs name
var totalCost = 0;
for (var i = 0; i < multiRowVariableSet.length; i++) {
totalCost += parseInt(multiRowVariableSet[i].item_value);
}
g_form.setValue("total", totalCost);
} else if (calTotal == 'false') {
g_form.setValue("total", "");
}
and a UI policy to make the MRVS Read only
Please mark this helpful/correct if it worked out fine.
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 11:31 AM
It's tricky activating a client script when a MRVS row is added, edited, or deleted as there is not inherently something watching for those activities. An onSubmit script that applies to the MRVS can get the contents of the MRVS value on the parent form, but the timing of that results in the contents prior to the row that triggered the script, so that's no good.
You can try one of these approaches - some may be dependent on using Service Portal / ESC or the native UI:
https://www.servicenow.com/community/developer-forum/actions-after-a-mrvs-update/td-p/3031014
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 02:02 PM
Hi Brad,
Thanks for the reply,
in this case there are some fields depending on the estimated subtotal
I can't really use a OnSubmit script, it will really help if it's changing when a value is being changed in the MVRS or if there is any other way around it.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:47 PM
Hi @TarunChowdary ,
This is how I was able to achieve this, it is kinda workaround but should work fine in your case:
This is my sample form:
1. I have added a checkbox to calculate the total, since we dont have an event to determine the addition or deletion of records in the mrvs.
2. I run a client script when the calculate total button is true and make the mrvs readonly. Making it read only is important coz if it is not read only, users can add new records/delete records and we wont get the event(refer pt 1).
3. If they have to enter new record, then they have to uncheck the calculate total checkbox.
Client script on Catalog item:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var calTotal = g_form.getValue('calculate_total'); //calculate total is the checkbox
if (calTotal == 'true') {
var multiRowVariableSet = JSON.parse(g_form.getValue('item_list')); //mymrvs name
var totalCost = 0;
for (var i = 0; i < multiRowVariableSet.length; i++) {
totalCost += parseInt(multiRowVariableSet[i].item_value);
}
g_form.setValue("total", totalCost);
} else if (calTotal == 'false') {
g_form.setValue("total", "");
}
and a UI policy to make the MRVS Read only
Please mark this helpful/correct if it worked out fine.
Johnny
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 10:15 AM
Hi JonnySnow,
This is Great it totally works,
Thank you so much for the response