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

Sure...!!

Even your information was helpful for me...!!

Thanks for that too, if it helped you do mark it helpful...!! 🙂

I asked to know what did you manipulate to make it work. However logic is quite similar. 

Thank you! 🙂

Priya151
Kilo Contributor

Hi,

I have similar kind of requirement to make variables editable on catalog task form. I tried below code :

if(item =="CATALOG_ITEM_NAME" ) {
g_form.setVariablesReadOnly(true);
g_form.setReadOnly("variables.VARIABLE_NAME",false);

but its not working..

 

Shayon
Kilo Contributor

Hello Angshuman

You may wirte catalog client script for it.

My catalog tasks needed different fields to appear and also different fields to be made read-only for each task.

1. select "Applies on Catalog Tasks" before you start

2. I have considered the short description field as the identifying factor of my task:

my code is as follows:

"

function onLoad() {
var taskList = new GlideRecord('sc_task');
taskList.addQuery('short_description','XXXXX_Task');
taskList.query();
if(taskList.hasNext()){
g_form.setReadOnly('field1',false);
g_form.setMandatory('field1',true);
}
else{
g_form.setReadOnly('field1',true);
g_form.setMandatory('field1',false);
}
}

"

3. One thing has to be noted, when I did not add setMandatory it was not working but it worked once I added it. 

Please let me know if if anyone knows the reason why it only works with mandatory field and also if anybody has a better approach of achieving the same.