Return to Previous Window from DialogWindow

Chris M3
Tera Guru

I just finished development on a custom dialog window, and I'm having trouble with where it's going after the user clicks 'Ok' on the dialog window.

 

The dialog window pops up from a UI Action from a Form Link.   If they click cancel, it closes without doing anything as designed.   If they click Ok, a Processing Script is run to make some data updates, and I'd like it to return the user to the same form they were looking at before.   However it's directing them to a full page view of the UI Page with none of the data that was there previously.

 

Below are the relevant lines of code.

 

<g:dialog_buttons_ok_cancel ok="return resetTimers()"/>

 

Client Script

function resetTimers() {

    GlideDialogWindow.get().destroy();

    return true;

}

1 ACCEPTED SOLUTION

Sorry, the last 2 lines should be:



var urlOnStack = GlideSession.get().getStack().bottom();


response.sendRedirect(urlOnStack);



I had shortened it to just "response.sendRedirect(GlideSession.get().getStack().bottom());", which would work, but thought it might be too confusing.   I did not "undo" enough of the changes to get back to the above 2 lines.  


View solution in original post

8 REPLIES 8

justin_drysdale
Mega Guru

For simple redirection:


<g:dialog_buttons_ok_cancel ok="resetTimers()"/>


function resetTimer() {


GlideDialogWindow.get().destroy();


var URL = "/<your_form>.do";


window.location.href = URL;


}


No change to what's happening.   For more info, it's directing me to this page.


/ui_page_process.do?sys_id=43dd1f5b305b11c0223bb86d39e17e91



Do I have to do something in the processing script to allow redirection? Or should I move everything to the client script, even though there's nothing in the script the user needs to see or wait for?



Another option, is there a way in the UI Action to wait for and catch the response, and then run the processing script?


Adding these two lines to the end of the Processing script should do it:



GlideSession.get().getStack().bottom();


response.sendRedirect(urlOnStack);


Still nothing.   Here is the entirety of the code.. Maybe my mistake is somewhere else (was first time using Jelly)



And in case you're wondering after reading this.   This code is just to make life easier on the developers/testers when there are long timers in a workflow.   It displays the current timers for verification, and then resets them to 20 seconds so they trigger.



The UI Action:


function timerDialog() {


  sysId = gel('sys_uniqueValue').value;


  //Get the values to pass into the dialog


  //Initialize and open the dialog


  var dialog = new GlideDialogWindow("workflow_timer_dialog"); //Instantiate the dialog containing the UI Page 'workflow_timer_dialog'


  dialog.setTitle("Current Workflow Timers");


  dialog.setPreference("context_id", sysId);


  dialog.render(); //Open the dialog


}



The Jelly HTML:


<g:ui_form>


<g:evaluate var="jvar_context" expression="RP.getWindowProperties().get('context_id')" />


<g:evaluate var="jvar_timers" jelly="true">


  var exeTimers = new GlideRecord("wf_executing");


  exeTimers.addQuery("context", "${jvar_context}");


  exeTimers.addQuery("activity.activity_definition",   "3961a1da0a0a0b5c00ecd84822f70d85"); //Timer Definition


  exeTimers.query();


  var timerRows = '';


  while (exeTimers.next()) {


      var schedJob = new GlideRecord("sys_trigger");


      schedJob.addQuery("name", "WFTimer" + exeTimers.sys_id.toString());


      schedJob.query();


      if (schedJob.next()) {


          timerRows += '<tr><td>' + exeTimers.activity.getDisplayValue() + '</td><td>' + schedJob.next_action.getDisplayValue() + '</td></tr>';


      }


  }


  timerRows;


</g:evaluate>


<table>


  <tr>


      <td>Current Timers</td>


      <td>Current Endtime</td>


  </tr>


  ${jvar_timers}


  <tr><td colspan="2" style="color: red; font-weight: bolt; text-align: center;">Click Ok to End Current Timers</td></tr>


  <tr>


      <td colspan="2" align="center">


          <input type="hidden" name="context_id" value="${jvar_context}" />


          <g:dialog_buttons_ok_cancel ok="return true"/>


      </td>


  </tr>


</table>


</g:ui_form>



Processing Script:


gs.log('Testing Timers: ' + context_id);


var gdt = new GlideDateTime();


gdt.addSeconds(20);


var exeTimers = new GlideRecord("wf_executing");


exeTimers.addQuery("context", context_id);


exeTimers.addQuery("activity.activity_definition",   "3961a1da0a0a0b5c00ecd84822f70d85"); //Timer Definition


exeTimers.query();


while (exeTimers.next()) {



    var schedJob = new GlideRecord("sys_trigger");


    schedJob.addQuery("name", "WFTimer" + exeTimers.sys_id.toString());


    schedJob.query();


    if (schedJob.next()) {


          schedJob.next_action = gdt;


          schedJob.update();


    }


}


GlideSession.get().getStack().bottom();


response.sendRedirect(urlOnStack);