Making Variables editable on Catalog Task Form

Angshuman3
Mega Guru

Hi All,

Is it possible to to make variables editable on catalog task form based on user roles by using Client Script??...

The requirement is some variables should be editable for ITIL users 

Can someone help me with this?

Thanks and Regards,
Angshuman

1 ACCEPTED SOLUTION

Bhawana Upreti
Tera Guru

Yes, It is possible. You can write a client script like if user has role set field to writable else readable.

      var rqdrole = g_user.hasRole('RoleName');

       if (rqdrole){

              g_form.setReadonly('fieldname',false);

       }

Hope this helps.

Thanks.

   

View solution in original post

18 REPLIES 18

apoorva_tewari
Mega Guru

yes you can do it via UI policy and client script.

function onLoad(){
  var requestedfor = g_form.getValue('requested_for');
var gr= new GlideRecord ('sys_user_has_role');
gr.addQuery('user',requestedfor);
gr.query();
while(gr.next())
{
if <condition>
g_form.setReadonly('incident_state',true);
    g_form.setReadonly('impact',true);
    g_form.setReadonly('urgency',true);
    
}

also refer to below link:-
https://docs.servicenow.com/bundle/jakarta-application-development/page/script/useful-scripts/refere...

Hi,

I have tried using UI policy both using Run Script and normal UI Policy action, its not working and I am not sure if dot walking is allowed in UI Policy as I used "g_form.setReadonly('variables.variable_name',false)" .

I have also tried the following client script in Catalog Task table :-

function onLoad(){
   if (g_user.hasRole('itil')){

      g_form.setReadonly('fieldname',false);

   }
}

it still didn't work..... 😞

In the RITM form for the same catalog item all the variables are editable for Admin but Read-Only for ITIL users. But, in Catalog Task form it is required editable for both Admin and ITIL users. It is already editable for Admin but for the ITIL users its the same as in RITM Form.

Angshuman3
Mega Guru

Hi Guys,

I have tried using UI policy both using Run Script and normal UI Policy action, its not working and I am not sure if dot walking is allowed in UI Policy as I used "g_form.setReadonly('variables.variable_name',false)" .

I have also tried the following client script in Catalog Task table :-

function onLoad(){
   if (g_user.hasRole('itil')){

      g_form.setReadonly('fieldname',false);

   }
}

it still didn't work..... 😞

In the RITM form for the same catalog item all the variables are editable for Admin but Read-Only for ITIL users. But, in Catalog Task form it is required editable for both Admin and ITIL users. It is already editable for Admin but for the ITIL users its the same as in RITM Form.

Thanks,
Angshuman

Please correct syntax to setReadOnly from setReadonly.

Thanks.

Hey,

That was a type here.....
I had typed setReadOnly, but it didn't work actually.