Make variables Readonly in one task and editable in other task

Harish74
Tera Expert

Hi there, I have some variables. I want to make them visible & editable in one task and Visble and read-only in the other tasks.

5 REPLIES 5

Michael Jones -
Giga Sage

Does your task have a consistent short_description or some otherwise easily identifiable, distinguishing feature? You can write a Catalog Client Script that makes those particular variables read-only if that particular condition is not met. Just mark the task only as applies on catalog tasks. 

You can then use statements like: 

var short_desc = '';

short_desc = g_form.getValue('short_description');
if(short_desc == 'Your short description') {
//your read-only code here
}

Obviously the details would need to be worked out, but the general idea works. 

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Harshal Gawali
Giga Guru

Hello Harish,

If you have distinguishable short_description on catalog task then using UI policy you can make them editable for particular task and read-only for other task.

Make sure that applies on catalog UI policy checkbox should be true

find_real_file.png

Also make run script check box true. write code as per your use case.

For reference check below example.

function onCondition() {

if(g_form.getValue('short_description')=='Test Incident')
{

g_form.setReadOnly('field_name',false);

}
else
{

g_form.setReadOnly('field_name',true);

}

}

 

Regards,

Harshal.

Hi Harshal,

 

I followed your example above and when I test it, it is hiding the new_email_address field variable on my tasks

function onCondition() {

if(g_form.getValue('short_description')=='Create Email with Name Change')
{

g_form.setReadOnly('new_email_address',false);

}
else
{

g_form.setReadOnly('new_email_address',true);

}

}

The Run Script check box is checked

Applies on Catalog Tasks.

I didnt set any catalog conditions, I figured that is what the script was doing.

 

Do you have any thoughts on my this might be happening?  

Thank you

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Harish,

Approach

1) create 1 UI policy which Applies on Catalog Task

Condition: Short description is [your task1 short description]

UI Policy Action: visible and readonly false

2) create another UI policy which Applies on Catalog Task

Condition: Short description is [your task2 short description]

UI Policy Action: visible and readonly true

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader