dynamic filter using a catalog item variable question

jack_zheng
Kilo Expert

Hi All

 

Is it possible to create a dynamic filter using a catalog item variable question?

 

For example, I have a simple catalog item with 2 variable questions:

  • RequestedFor (reference field to the sys_user table)
  • Employee (reference field to the sys_user table)

 

I want to create a dynamic filter on Employee similar to "Employee is(dynamic) me"

Instead of the dynamic filter options "me", I want to create a new dynamic filter options called "RequestFor".  The new filter for Employee will be "Employee.Manager is(dynamic) RequestFor"

Dynamic filter options "RequestFor" calls a script includes "getRequestFor".

Script includes "getRequestFor":

is Client Callable

function getRequestFor() {

//how do I get the value of the variable.RequestedFor?

//I tried return g_form.getValue("variables.RequestedFor") and it doesn't work .

//http://wiki.servicenow.com/index.php?title=Client_Script_Access_to_Variable_Fields_on_Task_Records#g...

 

 //I tried return current.variables.RequestedFor and it doesn't work.

}

I did get advanced qualifier to work using a different script include.  Just curious if it's possible to do it as a dynamic filter instead.

4 REPLIES 4

andrewpilachows
Kilo Guru

Do you want to filter the available results in the Employee select list/reference field based on who is logged in, or have Employee depend on Requested For?


Requested for


Dynamic filters are more for static lookups I believe.   While it dynamically determines the value when it loads, I don't see how its going to work as a dependency where the value changes.



While I haven't tested in Service Portal where this type of solution may or may not work, you can use the combination of reference qual and variable attributes to have a dependent field update as the reference changes.   This will get you a script-less solution if that's why you wanted to try to use a dynamic filter.


find_real_file.png



The fail-safe way would of course be to use a script include and an onChange script using GlideAjax.   The script include would return a JSON array of the select list options and the onChange script would replace the select list.  


Get short_description in g_form.addOption String


shivanipatel
ServiceNow Employee
ServiceNow Employee

Jack,



We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.



If you feel that your question was answered, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This allows other customers to learn from your thread and improves the ServiceNow Community experience.



If you are viewing this from the Community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thanks,


Shivani Patel


Unknown-1.png