- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 10:18 AM
Hi,
As of now, the change request in my instance could be canceled in two ways :
1.) Moving the State to Canceled
2.) Cancel Button on the form (not the OOB cancel change. I have created my own according to my requirement).
I want 5 of the fields not to be mandatory on the form while clicking the cancel button or moving state to Canceled.
Those fields are shown in the snapshot below :
I have edited my UI Policy so that these fields would be mandatory in all states except Canceled. This does not show those fields as mandatory when the state moves to Canceled.
But, when I open a new change form (not filling any mandatory fields) and click the cancel button, I am being asked to fill in the ones (the five fields shown above) which I thought should not be mandatory while canceling.
Do I need to add extra code to the UI Action so that when cancel button is clicked, it would ask to fill other mandatory fields but not these five?
In that case, my UI Action code reads the following :
function cancelChange(){
if(!g_form.isMandatory('work_notes')){
g_form.setMandatory('work_notes',true);
g_form.addErrorMessage('Work Notes is Mandatory while canceling change');
return "";
}
gsftSubmit(null, g_form.getFormElement(), 'AST:AST:CHG-CancelButton');
}
if (typeof window == 'undefined'){
current.state = 4;
action.setRedirectURL(current);
current.update();
}
Please guide me in solving this. Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 10:31 AM
can you add this line to move state to cancelled immediately in the client, then the UI policy will not enforce the mandatory fields....
function cancelChange(){
g_form.setValue('state',4);
if(!g_form.isMandatory('work_notes')){
g_form.setMandatory('work_notes',true);
g_form.addErrorMessage('Work Notes is Mandatory while canceling change');
return "";
}
gsftSubmit(null, g_form.getFormElement(), 'AST:AST:CHG-CancelButton');
}
if (typeof window == 'undefined'){
current.state = 4;
action.setRedirectURL(current);
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 10:24 AM
in the client part can you make state 'cancelled' there, then the ui policy condition won't fire
g_form.setValue('state','cancelled');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 10:28 AM
Thanks for the reply mguy, but I did not understand what you were trying to say. Could you please put it more detailed as I am very new to Servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 10:31 AM
can you add this line to move state to cancelled immediately in the client, then the UI policy will not enforce the mandatory fields....
function cancelChange(){
g_form.setValue('state',4);
if(!g_form.isMandatory('work_notes')){
g_form.setMandatory('work_notes',true);
g_form.addErrorMessage('Work Notes is Mandatory while canceling change');
return "";
}
gsftSubmit(null, g_form.getFormElement(), 'AST:AST:CHG-CancelButton');
}
if (typeof window == 'undefined'){
current.state = 4;
action.setRedirectURL(current);
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2017 10:37 AM
Thank you very much mguy. It worked.