The CreatorCon Call for Content is officially open! Get started here.

read only is not working

siva44
Tera Contributor

Hai To All,

I have created one onload client script and ui policy as follws

1.onload client script:create a onload client script for read only impact and urgency fields based on the role

 

      

function onLoad() {
    //Type appropriate comment here, and begin script below
    var st = g_form.getValue('state');
    if (g_user.hasRoleExactly('priority manager') && (st != 6 || st != 3)) {
         setTimeout(function() {g_form.setReadonly('urgency'false);}, 0);
         setTimeout(function() {g_form.setReadonly('impact'false);}, 0);
        //  g_form.setReadonly('urgency', false);
        //  g_form.setReadonly('impact', false);
     } else {
         setTimeout(function() { g_form.setReadonly('urgency'true); }, 0);
         setTimeout(function() { g_form.setReadonly('impact'true); }, 0);
        // g_form.setReadonly('urgency', true);
        // g_form.setReadonly('impact', true);
     }
}
 
2. ui policy: read only all fields for resolved state
but in the resolved state impact and urgency fields are not read only it is not working when log in the user have which role mentioned in the onload client script
Thanks@ Regards
siva
1 ACCEPTED SOLUTION

Peter Bodelier
Giga Sage

Hi @siva44,

 

You need to change the OR to AND in the if statement. it is either not 6 or not 3 so it is always returning true.

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var st = g_form.getValue('state');
    if (g_user.hasRoleExactly('priority manager') && (st != 6 && st != 3)) {
         setTimeout(function() {g_form.setReadonly('urgency', false);}, 0);
         setTimeout(function() {g_form.setReadonly('impact', false);}, 0);
        //  g_form.setReadonly('urgency', false);
        //  g_form.setReadonly('impact', false);
     } else {
         setTimeout(function() { g_form.setReadonly('urgency', true); }, 0);
         setTimeout(function() { g_form.setReadonly('impact', true); }, 0);
        // g_form.setReadonly('urgency', true);
        // g_form.setReadonly('impact', true);
     }
}

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

View solution in original post

2 REPLIES 2

Peter Bodelier
Giga Sage

Hi @siva44,

 

You need to change the OR to AND in the if statement. it is either not 6 or not 3 so it is always returning true.

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var st = g_form.getValue('state');
    if (g_user.hasRoleExactly('priority manager') && (st != 6 && st != 3)) {
         setTimeout(function() {g_form.setReadonly('urgency', false);}, 0);
         setTimeout(function() {g_form.setReadonly('impact', false);}, 0);
        //  g_form.setReadonly('urgency', false);
        //  g_form.setReadonly('impact', false);
     } else {
         setTimeout(function() { g_form.setReadonly('urgency', true); }, 0);
         setTimeout(function() { g_form.setReadonly('impact', true); }, 0);
        // g_form.setReadonly('urgency', true);
        // g_form.setReadonly('impact', true);
     }
}

Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Tq so much  peter now it is working fine