Help with an Advanced Reference Qualifier & Client Script for MRVS

Lon Landry4
Mega Sage

Can someone help me with an Advanced Reference Qualifier & Client Script for MRVS?
I believe the syntax is correct, so it must be something else...


I am trying to create an Advanced Reference Qualifier in the global scope for a catalog item, that removes an option (record) from MRVS query if already selected. I am getting the data I need, and I believe it is available when I need it.

 

What I know:

  • I have tested using alerts & am currently copying the list of MRVS records to a placeholder variable in the MRVS.
  • A sys_id or list of sys_id s are captured in a place holder field.

I have tried using the following variable types for a placeholder variable:

  • Single line text returns list of Sys Ids separated by a comma.
  • Multiline text returns list of Sys Ids separated by a comma.
  • Reference is empty.
  • List collector returns list of display_name s separated by a comma.


onLoad Client script (Isolate script is false)

function onLoad() {
//Get whole JSON payload from MRVS
var inList = g_service_catalog.parent.getValue('u_returning_asset_submitted_for');
//If MRVS is not empty
if (inList !=''){
//Create a placeholder/test variable
var testInList = inList;
//Create a variable to handle regex with name of MRVS variable value to extract
var regexInList = /assets_assigned_to_submitted_for":"(.*?)"/g;
//Add data retuned from regex to an array
var dataInList = [];
//loop thru MRVS data & return Sys IDs in a comma seperated list
var checkInList;
while(checkInList = regexInList.exec(testInList)){
dataInList.push(checkInList[1]);
}
sessionStorage.setItem('assets_i_certify_filter',dataInList);
g_form.setValue('first_list_of_assets',dataInList)
}
//if MRVS is empty then do nothing
else{return;}
}

 

Advanced Reference Qualifier

javascript(and colon)'install_statusNOT IN7,8,17,^model_categoryNOT LIKEvm^model_categoryNOT LIKEServer^display_nameNOT LIKEvmware^assigned_to!=ddbd343f375acf809bfbdaa543990ea5^sys_idNOT INcurrent.variables.first_list_of_assets;^assigned_to=' + current.variables.tb_submitted_for;

 

Illustration of issue

Example of issue illustrated.
1. Initial list displayed to user inside of MRVS.
mrvsIssue2.png

2. User selects an option (Ex. Apple)
3. The next time uses selects Add, the option (Apple) is still in list.

mrvsIssue1.png

5 REPLIES 5

Appanna M
Tera Guru

Hello @Lon Landry4 ,

 

Please try with below for the advance reference Qualifier.

 

Advanced Reference Qualifier

javascript(and colon)'install_statusNOT IN7,8,17,^model_categoryNOT LIKEvm^model_categoryNOT LIKEServer^display_nameNOT LIKEvmware^assigned_to!=ddbd343f375acf809bfbdaa543990ea5^sys_idNOT INcurrent.variables.first_list_of_assets^assigned_to=' + current.variables.tb_submitted_for;

 

So you don't want the option available in the dropdown for next time? Refer below.

https://www.servicenow.com/community/service-management-forum/how-to-hide-selected-dropdown-choice-i...

 

Please Mark My Answer as Helpful and Accept as Solution, if you find this article helpful or resolves your issue.

 

Hello @Lon Landry4 ,

 

Please Accept as Solution if it helps you.

 

Hi Appanna,
Thanks for reaching out.

I have same issue as other users (see reply chain).

Error:ReferenceError: (variable name) is not defined.

Thru alerts - Whole JSON returned with Variable set internal name.

On the individual variable - nothing is retuned.

Any ideas?


The above issue is why I usually resort to regex because the whole JSON string available...
My guess is that ServiceNow did not test g_service_catalog.parent.getValue(); in the global scope.

Murthy Ch
Giga Sage

Hello @Lon Landry4 

I don't think this is something not possible to acheive this scenario like using reference qualifiers.

I would suggest you to utilize the use of MRVS Unique option which is provided by ServiceNow (OOB).

Unique.png

It prevents you to do not select the same values with in the MRVS.

Hope it solves your query. Post here if you need more help.

 

Thanks,
Murthy