Clearing mandatory fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 01:27 AM
Hi,
We have various hidden fields that become active and mandatory on certain status changes (resolved, assigned to 3rd party etc) if someone has selected the status by mistake when they switch to the correct status the fields stay mandatory and the user has to come out of the ticket without saving and go back in. Any ideas on how to resolve this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 01:39 AM
The Reverse if False Checkbox of UI policy is created for this purpose. See Creating a UI Policy - ServiceNow Wiki
If the state changes back, the field becomes non mandatory as it was made mandatory by the UI policy.
In case you are making the fields mandatory using client script, you will need to write an else condition to make it non mandatory again.
g_form.setMandatory(<field_name>,false);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 02:06 AM
Hi,
So there are only a couple of fields that wont reset, one of which
controlled by a client script and does end with the g_form script. full
script is included below. The vendor action field become mandatory when
assigned to a specific vendor, if I re-assign it remains mandatory. I will
look into the other fields that do not clear and come back to you both.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
//var vendorAction = g_form.getValue('u_vendor_action');
//alert(newValue);
//alert(oldValue);
var assGroupDisplay = '';
var oldAssGroupDisplay = '';
var sccCompany = g_form.getValue('u_vendor_company');
//var oldassGroupDisplay = '';
var gr = new GlideRecord('core_company');
gr.query('sys_id',newValue);
while (gr.next()){
assGroupDisplay = gr.name;
}
var gr1 = new GlideRecord('core_company');
gr1.query('sys_id',oldValue);
while (gr1.next()){
oldAssGroupDisplay = gr1.name;
}
if ((assGroupDisplay != 'SCC Engineering' && oldAssGroupDisplay ==
'SCC Engineering' && sccCompany != '') || (assGroupDisplay == 'SCC
Engineering' && oldAssGroupDisplay != 'SCC Engineering' && sccCompany
!= '')){
g_form.setMandatory('u_vendor_action', true);
}else{
g_form.setMandatory('u_vendor_action', false);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 01:43 AM
Hi Steve,
Can you please confirm how are you setting fields mandatory?
Based on the conditions only "UI Policy" are applicable to the form.
Kindly go through the below wiki link
http://wiki.servicenow.com/index.php?title=Creating_a_UI_Policy
Please let me know if you have any questions.
Thanks
Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2014 02:13 AM
Hi,
The other fields that do not reset are the closure code and closure notes
when setting a ticket to resolved. These are controlled by a UI action and
the reverse if false is ticked. Oddly if I open a new ticket and resolve
and then set the state back to new it clears the mandatory fields. if I
resolve a ticket that is open the mandatory flag does not reset. Your
thoughts would be appreciated.