UI Policy Script - ReadOnly fields

Kamran1
Kilo Guru

Hello Community,

I am trying to allow ITIL user to be able to edit incident due date. We have a UI policy in place which makes the due date mandatory or not mandatory based on contact type and status fields selected. However, when ITIL user selects a due date, and later on tries to change to a different due date, it gets greyed out. We have a UI policy script in place that restricts to change the due date as noted below. I want to edit the script so ITIL user can change due date once set to a different date. For example if contact type is phone and status is New or Active and similar other variations:

function onCondition() {

var isAdmin = g_user.hasRole('admin');

if (!isAdmin) {

g_form.setReadOnly('u_reported_by',true);

g_form.setReadOnly('caller_id',true);

g_form.setReadOnly('u_non_ad_user',true);

g_form.setReadOnly('location',true);

g_form.setReadOnly('u_due_date',true);

}

var isAllowedToUpdateLocation = g_user.hasRole('CW_UpdateIncidentLocation');

if(isAllowedToUpdateLocation){

g_form.setReadOnly('location',false);

g_form.setReadOnly('u_due_date',false);

}

}

Not experience in scripting, can anyone please provide few suggestions that I can play around with.

Thanks in advance!

1 ACCEPTED SOLUTION

She Sull
Giga Guru

Not sure if CW_UpdateIncidentLocation is an actual role on your instance, but if you just need itil and admin:



function onCondition() {



var isAdmin = g_user.hasRole('admin');


var isItil = g_user.hasRole('itil');



if (!isAdmin) {


g_form.setReadOnly('u_reported_by',true);


g_form.setReadOnly('caller_id',true);


g_form.setReadOnly('u_non_ad_user',true);


}



if(isItil){


g_form.setReadOnly('location',false);


g_form.setReadOnly('u_due_date',false);


}


}



Though you have to be careful with ui policy scripts because you need to ensure the fields are actually on the form and that there are no acls conflicting with your script. If Location and Due date are on the form and do not have any acl restricting them you don't need the isItil if statement.


View solution in original post

6 REPLIES 6

Great, after you create your script and test it let is know if you still need help. Thanks!


Kamran1
Kilo Guru

I am still waiting for the user feedback however with my test user and ITIL role with script modified it seems to work and I am able to modify the due date. Your support is greatly appreciated.



Kam