How to set Quantity in shopping cart of item based on variable without using DOM

Joshwa Antony S
Mega Guru

Hi All,

We want to set the Quantity of catalog item based on a variable in the item.

We wanted to achieve this without using DOM (gel, $, j$, getElementBy, g_form.getControl, g_form.getElement)

Is there any way to achieve the functionality without using DOM

Regards,

JAS

1 ACCEPTED SOLUTION

Joshwa Antony S
Mega Guru

Hi All,

Thanks for following up and for your valuable inputs.

I ended up stick with DOM. Yes I could have this validation in workflow and set the quantity in RITM but we are looking for more user friendly way of setting quantity and displaying that to user even before submission. Also we can't have more choices in quantity which is not looking great in classic view/native view of catalog items.

I came across one OOB API which may help others if they are looking to set quantity onchange of any variable in catalog item.

g_cart.setQuantity(10) ==> This API will allow us to set the quantity in UI itself, but the quantity choices should have the value that we are setting. Consider that the quantity choices are 1,2,3,4,5 in this case if we want to set 10 via g_cart.setQuantity(10) it wont work.

Once again thanks for the inputs and time.

Regards,

JAS

View solution in original post

12 REPLIES 12

Mohit Kaushik
Mega Sage
Mega Sage

Hi There,

You should be able to achieve this by using onChange client script and script include.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

without DOM I don't think it can be achieved

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

DirkRedeker
Mega Sage

Hi

You can go to the database tables, where the shopping cart is stored ("sc_cart" and "sc_cart_item").

There you have a "Quantity" field on the item table.

Maybe that helps you to modify the quantity you are looking for.

This can be done Server-Side by Script.

Let me know if that answers your question and mark my answer as correct/helpful, please.

BR

Dirk

 

Joshwa Antony S
Mega Guru

Dirk , Mohit, Ankur - Thanks for the reply.

sc_cart_item will create a entry for the record only on submission/add to cart.

So if I do onChange & GlideAjax - Ill not be having the entry in sc_cart_item to manipulate

If I do onSubmit & GlideAjax(Async) - The sc_cart_item might be removed when my onSubmit runs for manipulation. in this case also i wont be having that entry in sc_cart_item table.

Kindly correct if am wrong above.

Regards,

JAS