Display a variable in Tasks

KouassiP
Tera Contributor

Hello All , 

 

I have an item with 2 tasks and i want to make editable the vatiable in the Task 1 and in read only in the task 2 ... How is the best way to do this ?

Thank you for your support

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@KouassiP 

you can use onLoad normal client script on sc_task and not catalog client script

Check the task description and see if it's 1st or 2nd and then make the variable editable

function onLoad() {

    var shortDesc = g_form.getValue('short_description');
    if (shortDesc == 'task 1 short description') {
        g_form.setReadonly('variables.variableName', false);
    } else {
        g_form.setReadonly('variables.variableName', true);
    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

@KouassiP 

yes catalog task sc_task since you mentioned catalog item

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

6 REPLIES 6

@KouassiP 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

AJ-TechTrek
Giga Sage
Giga Sage

Hi @KouassiP,

 

As per my Understanding :-


Since variables belong to the catalog item and not directly to tasks, the usual way to handle this is to:
* Use UI Policies / Client Scripts on the Task form(s) to control the variable’s behavior based on the task type or other field.
* The variable remains the same on the parent request, but appears editable or read-only on each task, depending on context.

 

Solution


1. Identify the tasks
Assuming:
* You have an item → it creates two tasks (e.g., sc_task).
* Tasks might be differentiated by:
* A field like Short Description, Type, Assignment Group, or a custom field (e.g., Task Type = Task1 / Task2).
* Or just sequence: first created vs second created.

 

2. Create UI Policies on sc_task form
Go to:
ServiceNow → Service Catalog → Catalog UI Policies
* Table: sc_task
* Conditions:
* For Task 1 UI Policy:
* e.g., if Type is Task1 → set variable to editable.
* For Task 2 UI Policy:
* if Type is Task2 → set variable to read-only.

 

3. Add UI Policy Actions
Within each UI Policy:
* Add UI Policy Action:
* Select the variable → set to Read-only = true/false depending on need.
Note: Variables appear on sc_task if they’re displayed on the task form via Variable Editor.

 

4. (Optional) Use Client Script if logic is complex
If you can’t easily differentiate Task 1 vs Task 2 by a field:
* Use an onLoad Catalog Client Script to:
* Detect task type, order, or any custom logic.
* Set the variable’s read-only property dynamically.
Example:
function onLoad() {
var taskType = g_form.getValue('u_task_type'); // replace with your field
if (taskType == 'Task2') {
g_form.setReadOnly('variable_name', true);
}
}

 

How to differentiate Task1 and Task2?


Best practice:


* When creating tasks (e.g., via workflow or Flow Designer):
* Set a custom field like Task Type = Task1 / Task2
* Or set Short Description = Task1 or Task2 (then use this in condition)

Recommended approach


1. Keep the variable at the item/request level


2. Use UI Policies / Client Scripts on sc_task to control read-only behavior


3. Add a custom field or indicator to differentiate tasks


4. Avoid duplicating variables; control visibility/editability at task level

 

Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
 
Thank You
AJ - TechTrek with AJ
LinkedIn:- https://www.linkedin.com/in/ajay-kumar-66a91385/
YouTube:- https://www.youtube.com/@learnitomwithaj
ServiceNow Community MVP 2025