Javascript in condition doesn't work

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I'm trying to make a ui policy where some fields becomes read only if the user isnt a "manager" on the knowledge base that the article is connected to.

I'm doing like the picture below, but can't get it to work, no idea why.

ui policy 1.PNG

If I try this script in script-background it works as a charm.

var gr = new GlideRecord('kb_knowledge_base');

gr.addQuery('kb_managers','DOES NOT CONTAIN',gs.getUserID());

gr.query();

while(gr.next()){

gs.log("KB Base " + gr.title + " doesn't have your sys_id as manager");

}

Any clues?

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

There was an problem long back when the conditions of UI policy with fields would not work, unless it was added on the form layout. Not sure if this is related to that problem.



But please modify the form layout, dot walk the knowledge base field and add the manager list field to the layout. That would make the UI policy work



4-11-2016 7-53-19 PM.png


View solution in original post

7 REPLIES 7

JusCuz
Tera Guru

Did you try 'is not' instead of 'does not contain'?


"is not" isnt a option ... got "does not contain", "contains", "is empty" & "is not empty".


gs.getUserID function returns the sys_id of the user. try getting the sys_id of the manager- like


Knowledge base.managers.sys_id does not contain gs.getUserID()


Ahhh...sorry, didn't realize that was a list item.



Actually looking at this myself, I now see what you are saying. Dot-walking to this field from the article, the javascript does not appear to be evaluated. If I do a similar UI policy at the Knowedge base level itself against the managers field, that works, but dot walking it from the article in the condition builder it is not.