- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 01:48 AM
There are some UI Action (Form Buttons) available on my Problem ticket and they serve different purposes.
For example when I create a problem and fill the mandatory fields and click on Submit then the problem goes into a New state. Now come 3 UI Actions into picture. I need to click on Mark Open UI Action on the created problem so that state of the problem will change into an Open state for further progress. After this, there are 3 options on the ticket. Cancel problem, Create Change and Known Error. Upon clicking Known Error UI Action, a field becomes visible and mandatory (Knowledge Article reference field).
But if someone clicks on Known Error by mistake, there is no way the changes could be reverted. The field Knowledge Article remains mandatory and the ticket progress could not be made like if I wanted to Create Change or Cancel the incident. Below is the script for the same (OnSubmit😞
function onSubmit()
{
var grp = g_form.getValue('assignment_group');
var grpname = 'Manager Group';
if(g_form.getActionName().toString() == 'mark_open')
{
if(g_form.getValue('assignment_group') == '')
{
alert('Please fill the assignment group');
return false;
}
}
//Make knowledge article field mandatory on Known error
if(g_form.getActionName().toString() == 'known_error')
{
var knowledge = g_form.getValue('u_knowledge_article');
if(knowledge == '')
{
g_form.setVisible('u_knowledge_article', true);
g_form.setMandatory('u_knowledge_article', true);
g_form.flash("u_knowledge_article","#FFFACD",0);
alert('Please fill the required mandatory field');
return false;
}
}
if(g_form.getActionName().toString() == 'resolve_problem' && g_form.getValue('u_knowledge_article') == '' && g_form.setMandatory('u_knoweldge_article', true))
{
g_form.setVisible('u_knowledge_article', false);
g_form.setMandatory('u_knowledge_article', false);
g_form.setMandatory('u_solution',true);
//return true;
if(g_form.getValue('u_solution') == '')
{
alert('Please fill the required mandatory field');
return false;
}
}
}
-------------------------------------------------------------------------------------
I desire to cancel the incident or create a change on the Problem ticket even after I click on Known Error by mistake and the Knowledge Article field should become invisible and become non mandatory as well. Thanks for any help. | Gourav
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2015 08:08 AM
Hi Gourav,
Why are you not using script field in the UI action to write respective logic? You can write server side code as well as client side code there.
Instead of making your onSubmit() client script complicated I would suggest writing it in UI actions making it simple to develop, analyse and maintain.
Check this link for help- Client & Server Code in One UI Action - ServiceNow Guru
Here is a possible solution to your issue-
Once you write the client code to make Knowledge Article field visible and mandatory in the Known Error button, you can write reverse i.e. making Knowledge Article field non-mandatory and invisible client side logic in the required buttons(i.e. Create Change & Cancel Incident buttons) before you go to server side code in the UI action(i.e. before gsftSubmit() is executed).
Please let me know if you need more help.
Thanks,
Tanaji
--Mark helpful/correct if it helps you solving your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 03:43 AM
else
{
if((g_form.getActionName().toString() != 'known_error') && (g_form.isMandatory('u_knowledge_article')))
{
g_form.setVisible('u_knowledge_article', false);
g_form.setMandatory('u_knowledge_article', false);
}
Replace the above code to
else
{
if(g_form.getActionName().toString() != 'known_error')
{
g_form.setVisible('u_knowledge_article', false);
g_form.setMandatory('u_knowledge_article', false);
}
Try putting alert inside this else and in the script for the "actionname" so that we can find what actionname is coming.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 03:51 AM
You can use UI policies as well, In the condition field you can choose the action name and perform this mandatory and visibility functionalities over there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 04:19 AM
Not working Priya. I put an alert and the alert is working fine for those UI Actions which are not Known Error but as soon as I click on Known Error and then to Change Request or Cancel Incident buttons, the same drama starts. Anyway, thank you very much for your valuable time and analysis.
UI Policy condition does not have any option for UI Actions, I think that is not possible. Thanks a lot.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2015 08:08 AM
Hi Gourav,
Why are you not using script field in the UI action to write respective logic? You can write server side code as well as client side code there.
Instead of making your onSubmit() client script complicated I would suggest writing it in UI actions making it simple to develop, analyse and maintain.
Check this link for help- Client & Server Code in One UI Action - ServiceNow Guru
Here is a possible solution to your issue-
Once you write the client code to make Knowledge Article field visible and mandatory in the Known Error button, you can write reverse i.e. making Knowledge Article field non-mandatory and invisible client side logic in the required buttons(i.e. Create Change & Cancel Incident buttons) before you go to server side code in the UI action(i.e. before gsftSubmit() is executed).
Please let me know if you need more help.
Thanks,
Tanaji
--Mark helpful/correct if it helps you solving your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2015 10:01 AM
Thanks a bunch Mr. Tanaji. Here is what I wrote in he UI Action script part after selecting Client checkbox and giving a function in OnClick: CancelProblem()
function CancelProblem()
{
var now = g_form.getValue('u_mcd_knowledge_article');
if(now == '')
{
g_form.setVisible('u_mcd_knowledge_article', false);
g_form.setMandatory('u_mcd_knowledge_article', false);
}
}
current.problem_state = '98';// cancelled
current.update();
action.setRedirectURL(current);
-----------------------------------------------------------------
Upon clicking Cancel Problem button after clicking Known Error, the field is first becoming non mandatory and then disappearing but the form does not return anything.