How can I call a UI Action from another UI Action?

eduardomendez
Kilo Explorer

Hey Everybody!

I need call a UI Action (TC_List) from another UI Action (Update).

Why?

The UI Action "TC_List" open a popup with the time card form, but when I save the form I need save the previous form (for this example INCIDENT FORM) too.

Add both UI Actions

TC_List

function showMyForm(){

var tableName = 'u_tiempo_real'; //specify the table for the Glide Dialog form  

var numero = g_form.getValue('number');  

  //Create and open the dialog form  

var dialog = new GlideDialogForm('TC', tableName); //Provide dialog title and table name  

dialog.setSysID(-1); //Pass in sys_id to edit existing record, -1 to create new record  

dialog.addParm('sysparm_view', 'default'); //Use the Add Inventory view of the form  

dialog.addParm('sysparm_form_only', 'true'); //Remove related lists  

  //Callback inserts values into the Computer record after data are returned from the server  

dialog.setLoadCallback(function(iframeDoc) {  

// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE  

var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;  

dialogFrame.g_form.setValue('u_num', number);  

});  

dialog.render(); //Open the dialog

      }

UPDATE

if((current.incident_state == 6 || current.incident_state == 😎 && current.close_notes.toString().length <30){

      gs.addInfoMessage(gs.getMessage("The number of characters in the field Close Notes must be greater than 30"));

      action.setRedirectURL(current);

     

} else if(current.incident_state == 3 && current.comments == '' && current.work_notes == ''){

      gs.addInfoMessage(gs.getMessage("You must complete the comment field or work notes field"));

      action.setRedirectURL(current);

}else {

              if(current.incident_state == 5){

              gs.eventQueueScheduled("IntervProgramada", current, gs.getUserID(), gs.getUserName(), current.expected_start);

      }

}

Any Idea!?

10 REPLIES 10

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Eduardo,



UI Actions are action based events. You can create a script include and call it in your code.


Hi Pradeep!



Yeah, but I tried this...



function showMyForm(){


var tableName = 'u_tiempo_real'; //specify the table for the Glide Dialog form  


//Get values from the Asset Receipt table  


var numero = g_form.getValue('number');  


 


//Create and open the dialog form  


var dialog = new GlideDialogForm('TC', tableName); //Provide dialog title and table name  


dialog.setSysID(-1); //Pass in sys_id to edit existing record, -1 to create new record  


dialog.addParm('sysparm_view', 'default'); //Use the Add Inventory view of the form  


dialog.addParm('sysparm_form_only', 'true'); //Remove related lists  


 


//Callback inserts values into the Computer record after data are returned from the server  


dialog.setLoadCallback(function(iframeDoc) {  


// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE  


var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;  


dialogFrame.g_form.setValue('u_num', numb);  


 


//Hide most of the fields so they don't appear on the form  


//dialogFrame.g_form.setDisplay('manufacturer', false);  


});       //Open the dialog


dialog.render();


      }


      current.update();



if((current.incident_state == 6 || current.incident_state == 😎 && current.close_notes.toString().length <30){


      gs.addInfoMessage(gs.getMessage("The number of characters in the field Close Notes must be greater than 30"));


      action.setRedirectURL(current);


     


} else if(current.incident_state == 3 && current.comments == '' && current.work_notes == ''){


      gs.addInfoMessage(gs.getMessage("You must complete the comment field or work notes field"));


      action.setRedirectURL(current);


}else {


              if(current.incident_state == 5){


              gs.eventQueueScheduled("IntervProgramada", current, gs.getUserID(), gs.getUserName(), current.expected_start);


      }


}




And nothing happened.


Can you help on this?

 

srinivasthelu
Tera Guru

Hi Eduardo,



Find the action name of update ui action and call it from TC_LIST UI Action.



Below is the code you need to add it at the end of ShowMyForm function.  



gsftSubmit(null, g_form.getFormElement(), ''ActionNameofupdateuiaction"); //MUST call the 'Action name' set in this UI Action