- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 10:04 AM
Hi All,
I have a variable which is displayed only on the catalog task form and I want to make it mandatory only when the State of the catalog task is updated to 'Closed Complete'.
In order to accomplish this I have a UI policy created which displays it only on the catalog task form and hides it elsewhere. Now the trouble I am having is how should I set up the condition where it should be mandatory only when the catalog task State changes to 'Closed Complete'?
Can it be done in the same UI policy or will I need a client script?
Any help would be appreciated.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 11:57 AM
I used a UI Policy to do this. I set the state to Closed complete and used this script
function onCondition() {
g_form.setMandatory('variables.preorder',true);}
And then the false version of this for the "reverse if condition is false".
I also had to add something to the "Close Task" button to ensure the UI Policy was checked before closing out the task utilizing that button. I believe I utilized this thread to accomplish that: https://community.servicenow.com/thread/183633
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 10:49 AM
Hi Pradeep,
Yes I will have to use onchange client script. Can you provide me with the code for the same please?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 10:51 AM
And also as I mentioned I want to make it mandatory when the catalog task state changes to 'Closed complete'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 11:00 AM
Here you go.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
alert(newValue);
var st = g_form.getValue('state');
if(oldValue != newValue && st == 3)
{
g_form.setMandatory('short_description', true);
}
else
{
g_form.setMandatory('short_description', false);
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 11:19 AM
Hi Pradeep,
What should I select under the 'Variable name' within the onchange client script.
I tried your above code but its not working.
I replaced short description with my custom variable which I have on the catalog item which I want to make it mandatory and force the fulfiller to fill it before they can closed complete the task. It's a reference type variable.
Am I missing something in my code which is why it is not working?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 11:22 AM
You might be making this a lot harder than it should be. Using a catalog UI Policy is going to be a lot easier than trying to script it, plus it's easier to manipulate if you ever need to make a change.