Run Script in UI Policy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 03:42 AM
Dear All,
A UI Policy populates a variable (let's say *Department*) based upon a condition. Visibility of this variable is working fine.
However, I want to make this variable mandatory based upon a different condition.
Following is blueprint of the requirement :
If (country -> Spain OR country -> France)
{
make Visible -> *Department*
{
If Requested User's profile has *Domain* -> Transport
then make *Department* -> mandatory
Else
{
Mandatory is not needed
}
}
}
To fulfill this requirement, I have used UI Policy for control on Visibility on *Department* (working fine)
To set this field as mandatory, I have used *Run Script* section of UI Policy.
Following is the script :
function onCondition() [Execute if True]
{
var gr = new GlideAjax('UserRecord');
gr.addParam('sysparm_name','setMandatoryField');
gr.addParam('sysparm_requestedfor',user);
gr.getXML(function () {
var check = gr.getAnswer();
if(check=='Transport')
{
g_form.setMandatory('department',true);
}
});
}
function onCondition() [Execute if False]
{
g_form.setMandatory('department',false);
}
However, *Run Script* section is not working as per the expectation.
Please let me know any possible suggestions.
Best Regards,
Puru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2018 08:40 AM
Just a quick glance, you have this:
gr.addParam('sysparm_requestedfor',user);
Where it uses "user" variable, but I can't see any definition of the that variable.
I have never seen getAnswer() being used with getXML() either. Not sure if that works either.
I usally go with the example here: https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GLAX-getXML_S
//Göran