Understanding Script Return Values

When execution of a script completes, the script sends the values stored in the scripts environment object back to Civic Platform. Some events have documented special values in the environment, which you can set to send information to the Civic Platform interface. The event documentation provides the names for these values and the expected input from your script.

In addition to the environment return values related specifically to the event there are some return values that are always available for you to set. You do not need to provide these parameters a value unless you want something specific to happen.

Note that there are both before and after events in Civic Platform. An event with a name that ends in “Before” means the event takes place before the user action updates the database. An event with a name that ends in “After” means the event takes place after the user action updates the database.

Because script return values can stop Civic Platform from continuing a user action, if you associate a script with an after event, the user action completes before the script has a chance to stop it. If you want to be able to cancel a user action, use a before event.

Topics:

ScriptReturnCode

This return value is a numeric value (ScriptReturnCode Values) which allows the script to choose one of several actions to occur after the script finishes.

Table 1. ScriptReturnCode Values
Value Action
0 Proceed as normal.
1 Request Civic Platform to stop the user action and return to the previous page.
2 Request Civic Platform to stop the user action and return to the main menu.
3 Request Civic Platform to stop the user action and proceed to the page designated by the ScriptReturnRedirection value.
4 Request Civic Platform to stop the user action and log user out.

ScriptReturnMessage

When this return parameter has a value, it displays to the user as a message when the Civic Platform user request, of which the script is a part, completes. You can use this function to send informative messages, or explanations of why an error occurred.

You can use HTML characters to format the message. The text of the returned message displays to the user in a popup window.

When you set the ScriptReturnCode parameter to something other than zero, you can set a value for ScriptReturnMessage to explain to the user why they are redirected from the normal flow of the Civic Platform interface.

ScriptReturnRedirection

When you set the ScriptReturnCode parameter to three, and you set a value for ScriptReturnCode, the script sets the URL of the browser to the value of the ScriptReturnRedirection parameter.