Get Catalog Item Name/Sys_id from multi-row variable set (MRVS)

newservicenowus
Tera Guru

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

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@newservicenowus 

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.

 

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

View solution in original post

4 REPLIES 4

Amit Gujarathi
Giga Sage
Giga Sage

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



Ankur Bawiskar
Tera Patron
Tera Patron

@newservicenowus 

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.

 

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

newservicenowus
Tera Guru

Thanks @Ankur Bawiskar 

I changed it slightly to use

g_service_catalog.parent.getValue('VARIABLE');

 

@newservicenowus 

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);
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader