Advanced Reference Qualifier on Service Catalog Item

LaurenceT
Tera Contributor

Hi there,

 

I'm currently working on a catalog item that includes a reference variable called "Requested_by" (sys_user), and another called "Asset" (alm_hardware). I'm trying to make it so the "Asset" variable only displays hardware assets that have an assigned to value, which is the same as the "Requested_by" variable.

 

I've tried the following advanced reference qualifier, but I'm having no luck.

 

javascript:"assigned_to="+current.variables.requested_for

 

I'm aiming to have the "Asset" variable only display hardware assets that are assigned to the user specified in the "Requested by" variable.

 

Thanks,

Laurence

11 REPLIES 11

Rafael Batistot
Tera Sage

Hi @LaurenceT 

To achieve this, you should use an advanced reference qualifier script on the "Asset" variable that filters based on the value of the "Requested by" variable.

Example script for the reference qualifier (Advanced: true):

var requestedBy = current.variables.requested_by;
if (requestedBy) {
    answer = "assigned_to=" + requestedBy;
} else {
    answer = "assigned_to=NULL";
}

 

Also, make sure to create a Catalog Client Script (onChange) on the "Requested by" variable to refresh the "Asset" variable dynamically:

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue == '') {
    return;
  }
  g_form.setValue('asset', '');
  g_form.refreshReference('asset');
}


This ensures the "Asset" list updates in real time when "Requested by" is changed.

Thanks for this @Rafael Batistot. I tried all of the above, but it's still not working. I also wanted to note, that when I do test this in the service portal, I see the following error message when the catalog item loads "Error: There is a JavaScript error in your browser console".

 

And when I open up the console, the error says "[SCRIPT:EXEC] Error while running Client Script "Asset Field Refresh": TypeError: g_form.refreshReference is not a function"

 

Thanks

Community Alums
Not applicable

hi ,

On your Asset variable, set the Advanced Reference Qualifier to:

 

javascript:'assigned_to=' + current.variables.requested_by

Unfortunately this doesn't work, the reference field doesn't have any available records, even though the requested by person has hardware assets assigned to them, thanks.