The CreatorCon Call for Content is officially open! Get started here.

How to prevent page reload in UI Action ?

balaram
Mega Contributor

How to prevent page reload on click of a UI Action ?

Thanks

Bala

1 ACCEPTED SOLUTION

You can achieve by using client functionality in UI actions



here is the sample script that check if there are any test cases under a test plan (current)



You can you the same logic for checking if change tasks are present



Go through this article


Client & Server Code in One UI Action - ServiceNow Guru


which explains you how the client side functionality works




function test_case()
{


  var test = new GlideRecord('tm_test_case_instance');
      test.addQuery('tm_test_plan', g_form.getUniqueValue());
      test.addQuery('active',true);
      test.query();


      if(test.next())
      {
          gsftSubmit(null, g_form.getFormElement(), 'plan_approval');
      }
     
      else
      {
          alert('Atlease one test case should be added to the list');
          return false;
      }




}


if(typeof window =='undefined'){
updateChange();
}


function updateChange(){

current.state = '3';
current.update();


action.setRedirectURL(current);
}


View solution in original post

4 REPLIES 4

Chuck Tomasi
Tera Patron

Hi,



Sorry, UI actions do a page reload when you do current.update() (save your changes).



What is the issue you are trying to solve?


Hi Chuck,



While submiting a change, I need to display an error message(should not do the current.update())   if there is no tasks under particular change request.



Now I'm able to display the error message , but it's disappearing with in 1 second and page is reloading.



I want to show that error message until user closes it.



Thanks


Bala


You can achieve by using client functionality in UI actions



here is the sample script that check if there are any test cases under a test plan (current)



You can you the same logic for checking if change tasks are present



Go through this article


Client & Server Code in One UI Action - ServiceNow Guru


which explains you how the client side functionality works




function test_case()
{


  var test = new GlideRecord('tm_test_case_instance');
      test.addQuery('tm_test_plan', g_form.getUniqueValue());
      test.addQuery('active',true);
      test.query();


      if(test.next())
      {
          gsftSubmit(null, g_form.getFormElement(), 'plan_approval');
      }
     
      else
      {
          alert('Atlease one test case should be added to the list');
          return false;
      }




}


if(typeof window =='undefined'){
updateChange();
}


function updateChange(){

current.state = '3';
current.update();


action.setRedirectURL(current);
}


Hi Balarammfs,



Can you share your code if possible ?