How to check logged in user role in UI Policy

pradeepgupta
Giga Expert

Is there way to check logged in user role in UI Policy. Actually based on the logged in users role, I wanted to make fields read only/editable using UI Policy.

Is there any way by which we can make UI policy to execute before Client script.

7 REPLIES 7

Hi Shane,



I have used script of UI Policy to get the role of logged in user.As per OOB functionality UI Policy executes after client script and I don't thing same can be changed.


I've used UI policies to govern fields based on role often enough. Sometimes, especially around Change management, ACLs are overly complicated and the process order from client script to UI policies may overwrite your client script from actually setting a field readonly/visible/etc.



For situations like this, I set the UI policy to Run Scripts and under Execute if true, run something like:


function onCondition() {


  var hasRole = g_user.hasRoleExactly('role_name');



  if (!hasRole) {


  var fields = g_form.getEditableFields();  


  for (var x = 0; x < fields.length; x++) {  


  g_form.setReadOnly(fields[x], true);  


  }


  }


}



Then the UI policy itself won't have any UI actions on it as the script will take care of your actions. I've used this method to ensure my UI policy script takes place after all the client scripts load (otherwise UI policies will undo whatever the CS does).


ProbirDas
Tera Expert

Dear Pradeep,



The order of execution of the client scripts is defined by the system unlike UI Polices and we don't have control over it.



Your requirement can be achieved through ACL more easily.



Regards,


Probir