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

Multiple OnClicks within a UI Action is it possible?

adam0907
Kilo Explorer

I have a UI Action called "Submit for Review" on a form that I want to execute 2 events when I clcik on it.

Event 1)Move the record onto a different phase

2)Send an Email to numerous people advising of the change of phase.

I use the following OnClick event to move the record to the next phase.

OnClick = moveToReview()

function moveToReview(){
  removeMandatoryFieldsReview();
  gsftSubmit(null, g_form.getFormElement(), 'move_to_review'); //MUST call the 'Action name' set in this UI Action
}

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

function moveToReviewServer(){
    action.setRedirectURL(current);
    current.state = '13';
    current.u_release_phase = 'In Progress';
    current.update();

But can I add another one into this script to send out emails ie

Onclick = sendreviewemail

function sendreviewemail(){
      var release_number = g_form.getValue("number");

//Initialize and open the Dialog Window
    var dialog = new GlideDialogWindow("email_preview_rel_in_prog");
    dialog.setSize(1200,1200);
    dialog.setTitle("Release Review Request Notification Preview");
    dialog.setPreference("release_number", release_number);
     
  dialog.render();

      action.setRedirectURL(current);

Appreciate any help with this.

Cheers Adam

8 REPLIES 8

adam0907
Kilo Explorer

I was intending on adding a Pop Up UI page with details that will be sent in the notification for them to review before sending, does that change the solution?



Cheers Adam


marcguy
ServiceNow Employee
ServiceNow Employee

I think so yes as you don't want to submit the record until the popup has been reviewed and edited?



maybe you can add the call to complete the UI Action into the GDW OK Button?



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


then destroy(close) the dialog


adam0907
Kilo Explorer

Thanks to both of you.



Have used the following UI Action Script


function sendToReview(){
removeMandatoryFieldsReview();
var release_number = g_form.getValue("number");


//Initialize and open the Dialog Window
    var dialog = new GlideDialogWindow("email_preview_rel_in_prog");
    dialog.setSize(600,600);
    dialog.setTitle("Release Review Request Notification Preview");


    dialog.setPreference("release_number", release_number);
     
    dialog.render();  

    action.setRedirectURL(current);


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



Combined with UI Page client script and processing script to create what I need



function onSubmit() {
//   GlideDialogWindow.get().destroy();
// Call the server function move_to_review which is defined in UI action 'Move to Review'
      gsftSubmit(null, g_form.getFormElement(), 'move_to_review');
          return true;
}


function cancel() {
    var c = gel('cancelled');
    c.value = "true";
    GlideDialogWindow.get().destroy();
    return false;
}



var sysid = '';      
var gr = new GlideRecord('rm_release');
      gr.addQuery('number', rel_number);
      gr.query();
      if(gr.next()){
            if (cancelled != "true") {
              gs.eventQueue('release.reviewrequestnotification', gr, gs.getUserID(), gs.getUserName());
            }
            sysid = gr.sys_id;
      }


response.sendRedirect('rm_release.do?sys_id='+sysid);
gs.addInfoMessage('Your release request has been sent. Please be patient - it may take a few minutes for the email to be received by all parties.');



Cheers Adam


Hey Adam, I am trying to implement something similiar with a GlideDialogWindow that updates the state field on a task. with a UI Action button/list choice. I should be able to make use of your code, but am wondering if you could give me a glimpse into your UI Page?



I tried to work with Client & Server Code in One UI Action - ServiceNow Guru   but apparently you can't do GlideDialogWindows with this method...


Q) Hello, is it possible to use implement somthing ismilar, with glidedialogwindow on a ui action (for example: cancel)...


A) It's not because once the UI action is clicked it's done. The dialog would then be running on its own and wouldn't have anything to do with the UI action that called it. You would want to set up your UI page with the necessary back-end code included in 'cancelProcess' instead. That's a bit more complex to explain the specifics of, but that's where it would need to be initiated from. [[Mark Stanger 12-12-2015, 06:05]]