Mandatory UI Policy For Certain Users

arobertson
Tera Guru

Hi All,

 

I have a UI policy that sets a few fields mandatory when a service alert is at post mortem stage. Our change manager has asked if these fields cannot be mandatory for him.

 

What would be the best way to action this? Can i set a true/false script inside the UI policy?

1 ACCEPTED SOLUTION

arobertson
Tera Guru

Managed to get it to work. I used the following code:



function onCondition() {


   


    var grpName = 'Service Assurance';


    var usrID = g_user.userID;


    var grp = new GlideRecord('sys_user_grmember');


    grp.addQuery('group.name', grpName);


    grp.addQuery('user', usrID);


    grp.query(groupMemberCallback);


   


    function groupMemberCallback(grp){


          if(grp.next()){


                g_form.setMandatory('u_actions_taken', false);


                g_form.setMandatory('u_lessons_learned___proactive_', false);


                g_form.setMandatory('u_root_cause', false);


                g_form.setMandatory('u_updated_documentation', false);


                g_form.setMandatory('u_vendor_report', false);


          }


    }


}


View solution in original post

5 REPLIES 5

mitchell_stutle
Mega Expert

You could use the UI Policy scripts and then just use an if statement to check for the change manager's sys_id, but if you did that you would have to remove the UI Policy Actions and use g_form.setMandatory inside of the UI Policy scripts. It might be easier to put this into an onLoad script.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

HI Alex Robertson



You can place the below script in your UI policy and make sure that "on Load and run scripts" options are checked.


Script:Place the below script in "Execute if true" condition script


function onCondition() {


var changemanager = g_user.userID;


  if(changemanager == '6816f79cc0a8016401c5a33be04be441')//replace sysid here with the change manager sysid in your instance


  {


g_form.checkMandatory = false;//make all mandatory fields false for the change manager.


  }


}



Let me know the outcome.


Hi Pradeep,



My fault in not explaining my question clear enough. I need this to be for anyone in the change management group not just for one person.



I guess i would still take their user id but then look up their groups?


arobertson
Tera Guru

Managed to get it to work. I used the following code:



function onCondition() {


   


    var grpName = 'Service Assurance';


    var usrID = g_user.userID;


    var grp = new GlideRecord('sys_user_grmember');


    grp.addQuery('group.name', grpName);


    grp.addQuery('user', usrID);


    grp.query(groupMemberCallback);


   


    function groupMemberCallback(grp){


          if(grp.next()){


                g_form.setMandatory('u_actions_taken', false);


                g_form.setMandatory('u_lessons_learned___proactive_', false);


                g_form.setMandatory('u_root_cause', false);


                g_form.setMandatory('u_updated_documentation', false);


                g_form.setMandatory('u_vendor_report', false);


          }


    }


}