To Fetch sys_id of the catalog item which is present in cart

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-25-2023 10:12 AM
Hi Team ,
I would like to know what code should be written in the server script of widget to get the "sys_id" of the catalog item that is present in the cart.
I have queried the sc_item_option table and i am trying to match the "cart_item" field with sys_id of the catalog item that is available in the cart but unable to do so.
Is there any way to achieve this ?Kindly let me know
If any clarification needed pls revert.
I will paste the screenshot below.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2023 02:48 AM
Hi Timi,
Thank you for the response.
I will tell the exact requirement that i am trying to satisfy.
I have a catalog item called "Whitelist IP " and according to the requirement this particular catalog item alone should cascade few variables like Requested for ,What is the business purpose ,etc to the shopping cart widget whenever the user click on "Add to Cart " button in the Sp portal.
So i took a clone copy of the shopping cart widget and made necessary code changes in the Server side and the HTML template for which i have attached the screenshot below.
The reason why i queried "sc_item_option" table is because only in this table all the variable values of the catalog item is getting stored but my problem is since the sys_id is dynamic for the cart_item field i could not match the sys_id in the server script of the widget.
Even i tried the script you posted but i still find it difficult to get the sys_id of the cart item that is present currently .
Any other script would u recommend to achieve this requirement?
(NOTE: I still have not started to work on the hiding part of the requirement ,will be useful if u provide input on this aswell)
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2023 08:05 AM
Hi Timi,
Thanks for your script as it helped me to cascade the variables from catalog form to Shopping cart widget.
And i do have another part that has be accomplished along with this ,which is just to display the Requested for variable only for a particular catalog item not for all.
Hope some script needs to be written in HTML Template and Server script to achieve .
I have attached the screenshot below which has the yellow part which should be hidden for all catalog items except for one (Whitelist IP ).
Can you provide me your input on this to write the script ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2023 08:26 PM
Hi @diNesh_M
Within the Options [sc_item_option] table, you can dot-walk to the Cart item [cart_item] field where you'll have the Item [cat_item] field to identify the associated Catalog Item.
So we can put one more query after the line 164 like below. (Similar to the variable, you can add more query condition to get the value of Requested for instead of retrieving and looping through all variables)
scItemOptionGR.addQuery('cart_item.cat_item', '<the_catalog_item_sys_id>');
//or for multiple
scItemOptionGR.addQuery('cart_item.cat_item', 'IN', '<the_catalog_item_sys_id>');
//variable
scItemOptionGR.addQuery('item_option_new.name', 'requested_for');
scItemOptionGR.addNotNullQuery('value');
scItemOptionGR.query();
//then you'll have the requestor value
if(scItemOptionGR.next()){
var userSysID = scItemOptionGR.getValue('value');
var grUser = new GlideRecord('sys_user');
if(grUser.get(userSysID)){
//User Record
}
}
It seems challenging to create a solution that works universally across different catalog items due to the variable name "Requested for [requested_for]". There's uncertainty regarding whether the requestor information is consistently named in that manner.
Cheers,
Tai Vu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2023 10:40 PM
Hi Timi,
I am able to cascade the variables from catalog form to Shopping cart page now and the issue is resolved.
But now i am presently trying to hide that variable called "Requested For" for all other catalog items except one (Whilelist IP).
I am not sure what script should be written in the div tag of HTML Template and in the server side to achieve this requirement.
Any input from your side will be helpful
For further clarification kindly revert
Thanks