Need to update the quantity field in catalog item

Savitha4
Tera Contributor

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.

1 ACCEPTED SOLUTION

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:

find_real_file.png

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

11 REPLIES 11

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.

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.

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);
}

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

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. 

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:

find_real_file.png

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke