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

Hi! Srinivas,



Thks, but I tried this and nothing happened, I redirect me to my previous form (a list) and takes no action on the form.


Brian Dailey1
Kilo Sage

Hi Eduardo,



All of the functions declared in your UI Actions (that match current conditions) are loaded into the page, so you can call on any function you've declared from another UI Action (or client script, etc.) within the same page, or on any Action name.



(i.e., "showMyForm()" is available to your other actions, if need be)




Thanks,


-Brian


I found this out accidentally, when I had two separate UI actions with the same function name...


Took me forever to work out that the functions were available in all actions!



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Yeah, I found this when I was trying to slim down my client-side code... I saw that many of the UI Actions were doing essentially the same thing (Close Complete, Close Incomplete, Cancel...) and wanted to generalize some of the functionality.



So I created a generalClosure() function and just call that from all the closing UIAs with a few specific arguments.... it cut my code on those by about 50-60%, I'd say.




-Brian


Brain,



What statement did you use to call the function in another UI actions?



Regards


-Norton