How to add Reference Qualifier to Record Producer Variable

Christine30
Tera Guru

Hello:

I have a script include which returns a list of Product Model (cmdb_model) sys_ids, and an associated dynamic filter.  I am able to use the dynamic filter to filter a List View.  I've attached the script include and related screenshots.

Now, I would like to use the same dynamic filter on a record producer variable which is a reference to the Product Model table,  but am unable to do this.  No dynamic filters are available for the record producer variable (see first screen shot below). 

I've tried to use this advanced reference filter instead of a dynamic filter :  "javascript: new getNameFromCategoryNew().getName("Laptops")", also with no success. 

I would also like to change the "hard-coded" "Laptops" argument to be the category selected by the user, and held in another record producer variable named model_category.  I have tried "javascript: new getNameFromCategoryNew().getName(producer.model_category)", but the value does not seem to be passed to the script include. 

Thank you for any help.

 

find_real_file.png

 

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Do you have the logs in the Script include? What do they log when you use this?:

javascript: new global.getNameFromCategoryNew().getName(current.variables.model_category.getDisplayValue());

 

Make sure there are no other variables or variable set named model_category. And change global to the scope your script include is in, for example:

javascript: new scopeapp.getNameFromCategoryNew().getName(current.variables.model_category.getDisplayValue());

View solution in original post

20 REPLIES 20

The sys_ids returned from the script include are those I want to be able to select. 

Can you log the return of the Script include? Just to check that it is indeed returning sys_idINxxxxxxxxx,xxxxxxxxxxx,xxxxxxxxx

 

If it only returns sys_id's you need to use the reference qualifier like so:

javascript: 'sys_idIN' +  new getNameFromCategoryNew().getName(current.variables.model_category);

 

Make sure to add the Attribute "ref_qual_elements=model_category" on the variable. Change model_category to the variable you use in the reference qualifier.

These are now the last two lines in the script include function:

    gs.info('sys_idIN'+ models);
    return 'sys_idIN'+models;

I ran this background script:

     javascript: new getNameFromCategoryNew().getName("Laptops")

And this log entry was created:

find_real_file.png

In the record producer, product_model is the variable to be restricted to the sys_ids returned by the script include.  model_category is the variable that is selected and passed to the script include. 

The ref qualifier on product_model is: 

     javascript: new getNameFromCategoryNew().getName(current.variables.model_category)

The variable attribute on product_model is:

    ref_qual_elements=model_category

When I run the record producer and select model_category "Laptops" and then select a product_model (which should be but isn't filtered to the two sys_ids returned by the background script), I don't get the list of sys_ids in the log.  I do get this entry in the log:

 

find_real_file.png

Can you share a print screen of the Advanced reference qualifier setup on the variable?

Yes, here it is.  I am running this from within a scoped application, I don't know if that makes a difference.  I would also really like to have the variables be inside a multi-variable set, but I've taken them out of the set for now to simplify things.  When I put them back into the set I'm assuming I will have to reference them as current.variables.muti-var-set-name.var-name but not sure.  Thanks.

 

find_real_file.png