Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Making field Mandatory on catalog task

Rocky5
Kilo Sage

Hey Experts,

I have RITM workflow which creates 3 catalog tasks, But, I wanted to make one field mandatory on only 1 catalog task and that field should be non mandatory on other 2 catalog tasks.

How can I achieve this?

Thanks,

Rocky,

13 REPLIES 13

I agree with Ankur.  Hopefully you have a specific short description on the task that so you can use that in a client script to make it mandatory on only that particular task.

Hi Rocky,

In addition to above you need to check the RITM sys_id as well so that this client script runs only for your catalog item

sample script below

function onLoad(){

var catalogItemSysId = g_form.getReference('request_item').cat_item;

var shortDescription = g_form.getValue('short_description');

// add your catalog item sys_id here and your specific short desc to compare

if(catalogItemSysId == '<Your Catalog Item SysId>' && shortDescription == 'Specific Value'){

g_form.setMandatory('field_name', true);

}

}

Regards
Ankur

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

Michael Jones -
Giga Sage

Is the short description consistent on your tasks?

You could use a catalog client script, set to only execute on tasks and check the value of g_form.getValue('short_description') and if it matches your task, set the variable you want mandatory with g_form.setMandatory();. 

It's not perfect, but it should get the job done for a one-off. 

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!

Brad Bowman
Kilo Patron
Kilo Patron

We have a client script on sc_task.  You can run this onChange or onSubmit if the field/variable should only be mandatory before the task closes, or onLoad otherwise.  To narrow it down to only this task on this catalog item, use something like this

if(g_form.getValue('request_item.cat_item') == '4f87518fdbec0f004a29df6b5e96195c'){ // sys_id of catalog item
 if(g_form.getValue('short_description') == 'Validate Build & Capacity'){ //task short description
  g_form.setMandatory('v_estimated_completion_date', true);
 }
}