How to make a field mandatory only on SC Task for a particular Catalog Item

Mahalakshmi Rav
Tera Contributor

Hi All,

I have a requirement where a catalog variable job_number should:

  • Not be visible on Catalog Item or RITM (achieved by a Catalog UI Policy).

    MahalakshmiRav_2-1755857839937.png

     

  • Be mandatory only on SC Tasks when:

    • Short description starts with "Create address book record"

    • Assignment group is ABC Group

What I tried:

  • Created a UI Policy on sc_task table with the below condition but no policy actions are given since its a catalog item variable.

  • Script used:

     
    function onCondition() { g_form.setMandatory('job_number', true); g_form.setVisible('job_number', true); }
    MahalakshmiRav_0-1755857656225.pngMahalakshmiRav_1-1755857678706.png

     

  • But this UI Policy is not working for my variable.

  • In our instance, I have seen other similar configurations working fine, but not for this one.

Can anyone help me understand why my SC Task UI Policy is not working for this catalog variable? Do I need to make additional settings for the variable to be recognized on SC Task?

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Mahalakshmi Rav 

the problem is you used a normal UI Policy on sc_task. Normal UI Policies can only control table fields. Catalog variables live in the Variable Editor, so they’re controlled by Catalog UI Policies / Catalog Client Scripts (with “Applies on Catalog Tasks” enabled), not by standard UI Policies.

 

Catalog Client Script (onLoad)

  1. Create a Catalog Client Script tied to the Catalog Item.

  2. Check Applies on Catalog Tasks.

  3. onLoad script:

 

Smaple Code
function onLoad()
{
var desc = (g_form.getValue('short_description') || '');
var startsOk = desc.indexOf('Create address book record') === 0;
var isABC = g_form.getValue('assignment_group') === 'PUT_ABC_GROUP_SYS_ID_HERE';
var requireIt = startsOk && isABC;
// For catalog variables, use the variable "name"
g_form.setDisplay('job_number', requireIt); // not setVisible()
g_form.setMandatory('job_number', requireIt);
}

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

7 REPLIES 7

Ravi Gaurav
Giga Sage
Giga Sage

Hi @Mahalakshmi Rav 

the problem is you used a normal UI Policy on sc_task. Normal UI Policies can only control table fields. Catalog variables live in the Variable Editor, so they’re controlled by Catalog UI Policies / Catalog Client Scripts (with “Applies on Catalog Tasks” enabled), not by standard UI Policies.

 

Catalog Client Script (onLoad)

  1. Create a Catalog Client Script tied to the Catalog Item.

  2. Check Applies on Catalog Tasks.

  3. onLoad script:

 

Smaple Code
function onLoad()
{
var desc = (g_form.getValue('short_description') || '');
var startsOk = desc.indexOf('Create address book record') === 0;
var isABC = g_form.getValue('assignment_group') === 'PUT_ABC_GROUP_SYS_ID_HERE';
var requireIt = startsOk && isABC;
// For catalog variables, use the variable "name"
g_form.setDisplay('job_number', requireIt); // not setVisible()
g_form.setMandatory('job_number', requireIt);
}

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Hi @Ravi Gaurav , This actually worked, Thank you 🙂

Hemanth M1
Giga Sage
Giga Sage

Hi @Mahalakshmi Rav ,

 

Can you apply the visibility logic first and then set the field to mandatory (when the condition is true), It doesn’t make sense to make a field mandatory before it becomes visible.

 

UI Action should work in this case (it has access to both fields and Variables)

 

 

 

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Ankur Bawiskar
Tera Patron
Tera Patron

@Mahalakshmi Rav 

normal UI policy on table doesn't allow you to select variables in UI policy action.

In script please use this and it will work with your current UI policy

The syntax to use variable is this g_form.setMandatory('variables.variableName', true);

function onCondition() {
    g_form.setMandatory('variables.job_number', true);
    g_form.setVisible('variables.job_number', 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