Blog

setRedirectURL and setReturnURL

What is the difference between a setRedirectURL and setReturnURL?  I see them used in conjunction a lot but I am not sure about the difference between them.   Here are the differences:

setRedirectURL and setReturnURL Difference

  • setRedirect() sets the next page that the user will see;

  • setReturn() sets what page the user will return to after they submit or hit Back on the next page they see.

Below is a "Copy Last Caller" button example for setRedirect and setReturn:

UI Action: 
Name: Copy Last Caller
Table: Incident
Active: true
Show Insert: true
Show Update: true
Form Context Menu = true
List Context Menu = true
Condition: current.incident_state != 7 && gs.hasRole("itil")
Script: 
var lastIncident = new GlideRecord("incident"); 
lastIncident.addQuery("sys_updated_by","=",gs.getUserName());
lastIncident.orderByDesc("sys_updated_on"); 
lastIncident.query(); 
if (lastIncident.next()) {
   var newIncident = new GlideRecord("incident");
   newIncident.caller_id = lastIncident.caller_id; 
   var sysID = newIncident.insert();
   gs.addInfoMessage("New Incident " + newIncident.number + " created");
   action.setReturnURL(current);
   action.setRedirectURL(newIncident);
}

Example: Copy Last Caller from Form

In the example below, after the user clicks "Copy Last Caller" from an Incident Form, the user will be "redirected" to the new Incident, and once they click Update, they will "return" to the previous Incident they were looking at.  If they right-clicked the Incident list to use "Copy Last Caller", they will be "return" to the Incident on the row they right-clicked on.

1. Copy Last Caller from Incident INC0000040

2. Redirected to New Incident INC0010013.

3. Click Update on Form.  Returned to INC0000040.  Without the setRedirectURL, will be returned to the incident list.