- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 12:17 AM
Hi
I'm wondering whether it's possible to access the catalog item name or sys_id fom a MRVS.
Purpose I would like to remove a specific option from a choice variable on the multi-row variable set but for only if it's for this 1 item or if there are any ideas how to achieve it.
Thanks
Solved! Go to Solution.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 02:14 AM
Do this
1) create a hidden text variable and place it at the end of the form i.e. highest order
2) then you can use onLoad catalog client script which runs on catalog item and get the sysId of that catalog item from URL and store that in hidden variable and hide it
3) then use onLoad catalog client script on MRVS and use this syntax to access the variable value and you will know which catalog item it is
window.parent.g_form.getValue(VARIABLE_NAME);
Also make sure isolate script of the client script is set to false
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 02:06 AM
HI @newservicenowus ,
I trust you are doing great.
Here's an example of how you can retrieve the catalog item name and sys_id from an MRVS:
// Assuming you have the sys_id of the MRVS
var mrvsSysId = '<MRVS_sys_id>';
// Query the MRVS table
var mrvsGR = new GlideRecord('sc_multi_row_variable_set');
mrvsGR.get(mrvsSysId);
// Check if the MRVS record exists
if (mrvsGR.isValid()) {
// Get the catalog item reference field from the MRVS
var catalogItemRef = mrvsGR.cat_item;
// Query the catalog item table
var catalogItemGR = new GlideRecord('sc_cat_item');
catalogItemGR.get(catalogItemRef);
// Check if the catalog item record exists
if (catalogItemGR.isValid()) {
// Retrieve the catalog item name and sys_id
var catalogItemName = catalogItemGR.getValue('name');
var catalogItemSysId = catalogItemGR.getValue('sys_id');
// Output the results
gs.info('Catalog Item Name: ' + catalogItemName);
gs.info('Catalog Item Sys ID: ' + catalogItemSysId);
} else {
gs.info('Catalog item record not found');
}
} else {
gs.info('MRVS record not found');
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 02:14 AM
Do this
1) create a hidden text variable and place it at the end of the form i.e. highest order
2) then you can use onLoad catalog client script which runs on catalog item and get the sysId of that catalog item from URL and store that in hidden variable and hide it
3) then use onLoad catalog client script on MRVS and use this syntax to access the variable value and you will know which catalog item it is
window.parent.g_form.getValue(VARIABLE_NAME);
Also make sure isolate script of the client script is set to false
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 03:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 03:49 AM
I think this line works for portal
g_service_catalog.parent.getValue('VARIABLE');
and this line will work in native
window.parent.g_form.getValue(VARIABLE_NAME);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader