sc_redir('app_name/url', parameter01; parameter02, 'target', 'error', 'modal_height', 'modal_width')

The sc_redir macro is used to create dynamic redirects between two applications or between an application and a URL, allowing the passing of parameters and control over how the destination application will be opened using the target parameter.

In form applications, the sc_redir macro can be used in events that depend on database updates, such as: onAfterInsert, onAfterUpdate, onAfterDelete, onBeforeInsert, onBeforeUpdate, and onBeforeDelete.
However, in these events, the sc_commit_trans() macro must be used before sc_redir to confirm the transaction; otherwise, the redirection will occur without the table changes being applied.

Parameters

Parameter Description Examples
app_name/url Receives the name of the destination application or URL to which the user will be redirected.
The values must be enclosed in double or single quotes.
sc_redir('app_name');
parameter_to_send

Allows passing values to the destination application in the format: parameter_name='value'.
You can use a application_field, variable or informa a fixed value.

If more than one parameter is passed, use a semicolon (;) as a delimiter.
Values should be retrieved as global variables in the destination application.

sc_redir('app_name', parm1=50);

Two parameters passed: sc_redir('aplx', parm1={clienteid}; parm2="xxx");
In 'aplx', values retrieved as global variables: [parm1] and [parm2].

target

Defines how the destination application/URL will be displayed.

  • _self: Opens the destination in the same tab (default if no value is specified).
  • _blank: Opens the destination in a new tab.
  • _parent: Opens the destination in the parent window, if the current page is in an iframe.
  • modal: Opens the destination in a modal window (this option is unavailable when using the macro in a Run button)
Specifying target without parameters:
sc_redir('app_name', , '_blank');

Using modal:
sc_redir('app_name', , 'modal', , '800', '600');
error Defines the behavior of the redirection in case of an error in the application.
  • 'E': Blocks the redirection if an error occurs.
  • 'F': Forces the redirection even if an error occurs.
sc_redir('app_name', , ' ', 'E');
modal_height Defines the height of the modal in pixels. This parameter is mandatory when using modal in the target parameter. sc_redir('app_name', , 'modal', , '800', '600');
modal_width Defines the width of the modal in pixels. This parameter is mandatory when using modal in the target parameter. sc_redir('app_name', , 'modal', , '800', '600');

 

Usage Examples


Example 1 - Simple redirection without parameters.
//Since only the application was specified, it will open in the same tab.
sc_redir('aplx');
Example 2 - Redirection with parameter passing.
//Four parameters are being sent to the destination application; these values must be retrieved as global variables: [parm1][parm2][parm3][parm4].
if (empty($variable)) { $variable = "documentation"; }
sc_redir('aplx', parm1={clienteid}; parm2="xxx"; parm3=$variable; parm4=10);
Example 3 - Using target without parameters.
//In this case, since no parameters are being sent to the destination application, the space should be left blank to specify the target.
sc_redir('aplx', , '_blank');
Example 4 - Using modal for the target parameter.
//It is mandatory to define the width and height when specifying modal in the target parameter.
//Only the values should be provided.
sc_redir('aplx', , "modal", '', '800', '600');
Example 5 - Example of use in form database transaction events.
//The sc_commit_trans macro must be used before sc_redir to confirm the transaction.
sc_commit_trans();
sc_redir('aplx', parm1={clienteid});
Example 6 - Redirection to a URL.
if ([glo_usr] == "test")
{
sc_redir(http://www.mypage.com.br);
}