- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2022 11:54 AM
Hello,
I need to update the quantity in a catalog item based on number of records in the reference field of a variable before submission. I think I need to write a onChange catalog client script .Kindly provide assistance in writing the script. Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2022 10:01 PM
Okay.
I don't think you can modify the quantity based on the change of Multi Row Variable Set.
Have tried in my PDI when you add a new Row in MVRS , I have not seen any method to get the length of it based in which you can set the quantity of the cat item.
What you can do if you need this to be done with an On Change Script then that On Change Script need to be written on some other variable on the form and then you can achieve this using an On Change Script.
For example, I have a Variable as "Requested For" which I am selecting after adding Rows in MVRS and it will work fine:
Below script can be used:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue) {
var multiRowVariableSet = JSON.parse(g_form.getValue('demo_variable_set')); // Replace "variable_set_1" with your Variable Set Name. Make sure to replace it with Name and not with Label of Multi Row Variable Set
var numberOfRows = multiRowVariableSet.length;
g_cart.setQuantity(numberOfRows);
}
//Type appropriate comment here, and begin script below
}
Make sure the Rows are added to your MVRS and then you are changing the other variable value:
This works for me in my PDI. Let me know if you are facing an issue.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2022 10:14 AM
Hello Saurav,
Thanks for the script. Yeah I'm checking it. But the quantity is the field what we see above above price option in service catalog. I'm looking for that field name.
Regards,
Savitha.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2022 09:46 PM
Hello Saurav,
I tried but it's not working. In the script include you've glided incident table. I'm confused what value I need to submit in the place of incident. Also I don't see the variable name in the dropdown list. Can I leave it blank. Please help me with this.
Also I'm attaching a screenshot of the field from which I need to update the quantity field.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2022 11:45 PM
Hi,
Looking at your screenshot it look like you are using a Multi Row Variable Set and based on the total number of Rows added you need to set the quantity of the Catalog item.
For this, write an On Submit Catalog Client Script on your catalog item and use the script below:
function onSubmit() {
//Type appropriate comment here, and begin script below
var multiRowVariableSet = JSON.parse(g_form.getValue('variable_set_1')); // Replace "variable_set_1" with your Variable Set Name. Make sure to replace it with Name and not with Label of Multi Row Variable Set
var numberOfRows = multiRowVariableSet.length;
g_cart.setQuantity(numberOfRows);
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2022 08:00 AM
Hi,
Thanks for the reply. The above script works. But we need to display the change in quantity before the request is submitted. Hence we can not use
onsubmit client script. Can you please help me with onChange client script.
Regards,
Savitha.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2022 10:01 PM
Okay.
I don't think you can modify the quantity based on the change of Multi Row Variable Set.
Have tried in my PDI when you add a new Row in MVRS , I have not seen any method to get the length of it based in which you can set the quantity of the cat item.
What you can do if you need this to be done with an On Change Script then that On Change Script need to be written on some other variable on the form and then you can achieve this using an On Change Script.
For example, I have a Variable as "Requested For" which I am selecting after adding Rows in MVRS and it will work fine:
Below script can be used:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue) {
var multiRowVariableSet = JSON.parse(g_form.getValue('demo_variable_set')); // Replace "variable_set_1" with your Variable Set Name. Make sure to replace it with Name and not with Label of Multi Row Variable Set
var numberOfRows = multiRowVariableSet.length;
g_cart.setQuantity(numberOfRows);
}
//Type appropriate comment here, and begin script below
}
Make sure the Rows are added to your MVRS and then you are changing the other variable value:
This works for me in my PDI. Let me know if you are facing an issue.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke