- 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 01:59 AM
Hi Gourav,
Place a else condition after the code
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;
}
Make the knowledge article field visible, mandatory false in the else part.
Thanks,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:31 AM
Thanks Priya for your valuable suggestions but that is not what I am looking for. Here is a screenshot to make you more clear about the issue:
Here if I click on Known Error then the Knowledge Article field would become visible as well as mandatory. But if someone actually wanted to do something else on the ticket and by mistake clicked on the Known Error button then too the Knowledge Article field uses to behave as earlier. It is not allowing me to move forward with the ticket means suppose I clicked on Known Error and actually I wanted to click on Create Change or Cancel Problem then too the same thing is happening on the form as if it were a known error because I have already selected Known Error UI Action. This should not happen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:48 AM
Hi Gourav,
If you have clicked the Known error button by mistake too, the script gets executed with the action name. In the above script your making the "Knowledge article" field mandatory once Known error button is clicked. As there is no script to reverse that logic, the mandatory and visible code remains the same even after you try to click other UI buttons.
Just write the else part by making mandatory and visible false.It should work.
Thanks,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 03:34 AM
No Priya, even that is not working. Here is what I did based on your suggestions:
function onSubmit()
{
// change assignment grp on mark open
var grp = g_form.getValue('assignment_group');
var grpname = 'Problem Manager Group';
if(g_form.getActionName().toString() == 'mark_open')
{
if(g_form.getValue('assignment_group') == '')
{
alert('Please change 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;
}
}
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);
}
//return false;
}
if(g_form.getActionName().toString() == 'resolve_problem')
{
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;
}
}
}
------------------------------------------------------
Do UI Policies work on these UI Actions?