Make variables Readonly in one task and editable in other task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 06:36 PM
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.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 07:11 PM
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!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 09:07 PM
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2022 03:01 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2020 09:37 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader