The CreatorCon Call for Content is officially open! Get started here.

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

Hi @Ankur Bawiskar , I tried but it's the same, I don't see the job number in the sc_task form

@Mahalakshmi Rav 

syntax is correct.

Any other UI policy is conflicting?

Make UI Type - ALL

Did you try adding alert in UI policy script and see if condition is getting satisfied?

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

@Mahalakshmi Rav 

I believe I also shared a working solution.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

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