Issue on Problem Management ticket.

gourav2
Kilo Expert

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

1 ACCEPTED SOLUTION

Tanaji Patil
Tera Guru

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


View solution in original post

13 REPLIES 13

Hi Gourav,



Please make your Cancel Problem UI action exactly as shown below. It will do the job.



Name- Cancel Problem


Action name- cancel_problem_action


Client- true


Onclick- CancelProblem();



Script-


//marked in Italic is what your code was missing


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);


  }


gsftSubmit(null, g_form.getFormElement(), 'cancel_problem_action');


}



if(typeof window = 'undefined')


        runServerSideCode();



function runServerSideCode() {


current.problem_state = '98';// cancelled


current.update();


action.setRedirectURL(current);


}



Thanks,


Tanaji



--Mark helpful/correct is it helps you solve your issue.


Thanks Mr. Tanaji and that worked flawlessly. Thank you so much.


Thats Great News!!


You are welcome