How do I trigger a UI policy based on a script?

joshuamayes
Giga Expert

Hi.   I'm trying to hide and display fields in a form based on some scripted logic.   But I can't seem to figure out how to actually apply that logic to a UI Policy in serviceNow.

I have this script:

--------------------------------------------

/** Author: Joshua Mayes - 2017-04-26

* This is a function to return an array of the values the available choices depend on.

**/

function u_getChoiceDependantValues(fieldName,tableName) {

  var dependentValues = [];

  var choice = new GlideRecord('sys_choice');

  choice.addQuery('name',tableName);

  choice.addQuery('element',fieldName);

  choice.addQuery('inactive',false);

  choice.addNotNullQuery('dependent_value');

  choice.query();

while(choice.next()){

  dependentValues.push(choice.dependent_value.toString());

  }

return dependentValues;

}

--------------------------------------------

So when I call it with u_getChoiceDependantValues('subcategory','incident') I get an array of categories like [hardware,software,investigation]

I thought I would just trigger the ui by saying If Category is one of javascript:myFunction(); but that doesn't seem to work.

Anybody got any ideas on what I should do?

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Hi,



Instead of UI Policy,you can develop client script and use g_form functions to display or hide form fields.


You can do GlideAjax call to script include and function in script include will return category values.



This category values can be compared to call g_form functions.



Regards,


Sachin


View solution in original post

1 REPLY 1

sachin_namjoshi
Kilo Patron
Kilo Patron

Hi,



Instead of UI Policy,you can develop client script and use g_form functions to display or hide form fields.


You can do GlideAjax call to script include and function in script include will return category values.



This category values can be compared to call g_form functions.



Regards,


Sachin