Coordinator

The Coordinator component calls other menu items, allowing a multi–menu-item workflow to be managed from a single stored procedure.

It uses a first-in, first-out action queue, populated by the Init call. The Coordinator executes menu items and makes callbacks to the stored procedure until the queue is empty, at which point it makes the Finished call. Callbacks may append new actions to the queue.

Coordinated Menu Items

Forward links connect the Coordinator to the menu items that it calls.

Restrictions on Coordinated Menu Items

  • The user must have permission to run the coordinated menu items.
  • The Coordinator cannot control menu items with a user interface (like NewEdit).
  • The Coordinator cannot control menu items that return files (like Download File).
  • The Coordinator does not respect:
    • Confirmation text
    • Validate parameters
    • Custom access control or logging
  • Menu items must not redirect the user:
    • Static forwarding on the menu item is ignored.
    • Dynamic forwarding attempts are blocked.
  • Menu items must not attempt to display a question dialog.
  • Menu items must not use ADMIN_UnselectAll. However, the Coordinator may use it from its Finished call instead.
  • Only the Coordinator itself appears in SoftadminApi.LogMenuItem - not the menu items it calls.

Allowed for Coordinated Menu Items

  • May return values to the Coordinator.
  • May use Lock during execution. If the Coordinator cannot obtain the lock, it terminates.
  • May show an error dialog. This terminates the Coordinator.

SQL

SQL Call: Init (mandatory)

May modify database: Yes

Resultset: Shared Callback Parameters (optional)

Table count: repeated zero or one time
Row count: exactly one row
Columns
BeginSharedParams mandatory any

This marker-column must contain NULL, and specifies that the columns following it will be passed as parameters to all subsequent calls to the component's stored procedure.

xxx optional any

This value will be passed back to the procedure as a parameter with the same name as its column.

Resultset: Actions (optional)

The actions initially put into the Coordinator's queue.

Table count: repeated zero or more times
Row count: zero or more rows
Columns
Action mandatory string

The name of the action. This will be returned to the stored procedure in the @Action parameter.

LinkAlias optional string

The alias of a link of type forward link. The link's target menu item will be executed by the Coordinator.

Omit or return NULL to trigger a call the Coordinator's procedure directly without calling a menu item first.

StopOnError optional bit

Set to 0 to have the Coordinator make the Store Error call if this menu item raises an error. The default is 1.

BeginPassingFields optional string

This marker-column must contain NULL, and specifies that the columns following it can be referenced by the forward link.

BeginExtraParams optional string

This marker-column must contain NULL, and specifies that the columns following it will be passed to the Coordinator procedure in its callback call.

SQL Call: Callback

For actions that specified a link alias, the callback call is made once the linked menu item has been executed.

Any values returned from the menu item can be found in a temporary table called #Result.

CREATE TABLE #Result
(
	Name nvarchar(max) NOT NULL,
	Value nvarchar(max) NULL
)

If the action did not specify an alias, the callback is made without executing a menu item first, and the #Result table is not present.

The call can optionally enqueue new actions, or it can terminate the coordinator early by forwarding. You may not return both actions and forwarding, but you may omit both.

May modify database: Yes

Parameters

@Action string
The name of the enqueued action executed.
@xxx string
Any callback parameters assigned to the action or as shared parameters.

Resultset: Shared Callback Parameters (optional)

Table count: repeated zero or one time
Row count: exactly one row
Columns
BeginSharedParams mandatory any

This marker-column must contain NULL, and specifies that the columns following it will be passed as parameters to all subsequent calls to the component's stored procedure.

xxx optional any

This value will be passed back to the procedure as a parameter with the same name as its column.

Resultset: Actions (optional)

Additional actions to enqueue.

Table count: repeated zero or more times
Row count: zero or more rows
Columns
Action mandatory string

The name of the action. This will be returned to the stored procedure in the @Action parameter.

LinkAlias optional string

The alias of a link of type forward link. The link's target menu item will be executed by the Coordinator.

Omit or return NULL to trigger a call the Coordinator's procedure directly without calling a menu item first.

StopOnError optional bit

Set to 0 to have the Coordinator make the Store Error call if this menu item raises an error. The default is 1.

BeginPassingFields optional string

This marker-column must contain NULL, and specifies that the columns following it can be referenced by the forward link.

BeginExtraParams optional string

This marker-column must contain NULL, and specifies that the columns following it will be passed to the Coordinator procedure in its callback call.

Resultset: Forwarding (optional)

If forwarding is returned it must be the only table. Returning forwarding will terminate the Coordinator.

Table count: repeated zero or one time
Row count: zero or one row
Columns
ADMIN_ErrorMessage optional string

Displays a user friendly error message to the user. This blocks any forwarding for the user.

ADMIN_InfoMessage optional string

Displays a user friendly info message to the user. When the user clicks OK the user is forwarded.

ADMIN_SuccessMessage optional string

Displays a user friendly success message to the user. When the user clicks OK the user is forwarded.

ADMIN_Dialog optional string

The dialog alias of a predefined dialog to show the user. Must be the first column in the result set table. Use multiple result set tables to combine with other forwarding.

Use the menu item "Admin > Dialogs" to register new dialogs or find aliases for existing ones.

<xxx> (for ADMIN_Dialog) optional any

Any column without special meaning in the result set with the first column ADMIN_Dialog will be used to make replacements of placeholders in the message and title text.

ADMIN_DebugInfo optional string

Additional information to show the developer when using ADMIN_Dialog.

<passing_field> optional string

Any column with no other specific meaning will be passed along to the menu item or link you are forwarding to.

ADMIN_CidStepsBack optional int

Number of steps in the page history to jump back after execution (the default being one step back). This value overrides any destination specified by the query string.

ADMIN_ReturnToMenuItem optional string

Jumps back to the menu item with this alias after execution. This value overrides any destination specified by the query string. If no prior menu item is found with the given alias, then an error is thrown.

ADMIN_Forward optional string

Displays a user friendly message and then forwards to the next menu item.

ADMIN_ForwardLink optional string

Alias of the link to forward to.

ADMIN_ForwardMenuGroup optional string

Alias of the menu group to show after execution (instead of former menu item). This value overrides any destination specified by the query string.

ADMIN_ForwardMenuItem optional string

Alias of the menu item to execute after execution (instead of former menu item). This value overrides any destination specified by the query string.

ADMIN_Message optional string

Displays a user friendly error message to the user.

ADMIN_PasteHtmlFromPopup optional string

Pastes HTML into an HTML editor. See ADMIN_SetFieldValueFromPopup.

ADMIN_SetFieldValueFromPopup optional string

Sets the value of the field specified in the menuitempopup call. Only select this column if menu item is opened in a popup.

ADMIN_ClosePopup optional bit

If this column is anything but NULL the popup will be closed. Only select this column if the menu item is opened in a popup.

Default: The default behavior is to step back inside the popup window and close it if there is nothing to step back to.
ADMIN_ClosePopupAndReloadOpener optional bit

If this column is anything but NULL the popup will be closed and the parent will be reloaded. Only select this column if the menu item is opened in a popup. Avoid using this feature if the opener is a newEdit as that may interrupt the user's ongoing input.

ADMIN_ClearHistory optional any

When the value is not NULL all navigation history is cleared and the user can't navigate back. This is only supported when forwarding to another menu item.

ADMIN_RefreshMenu optional bit

Will trigger a reload of the sidebar if the column is anything but NULL.

Cache optional string

Cache key to be cleared. Supports wildcards.

CacheUserId optional string

Either a user id or '%'.

Clears all caches (e.g. access permissions) related to the specified user id.

Use '%' to clear caches for all users.

OkButtonText optional string

Changes the text of the OK button when used with ADMIN_ErrorMessage, ADMIN_ConfirmWarning, ADMIN_ConfirmQuestion, ADMIN_ConfirmDelete, ADMIN_InfoMessage, ADMIN_SuccessMessage, ADMIN_Message, ADMIN_Force, or ADMIN_Forward. ADMIN_Force,

SQL Call: Store Error

By default, the Coordinator will stop if any called menu item raises an error. However, if an action was specified with StopOnError = 0, the Store Error call is made if that action fails.

The call can optionally enqueue new actions, or it can terminate the Coordinator early by forwarding. You may not return both actions and forwarding, but you may omit both.

May modify database: Yes

Parameters

@Action string
Set to 'StoreError'.
@ErrorMessage string
An error message describing the failure.
@FailedAction string
The name of the action that raised an error.
@xxx string
Any callback parameters assigned to the action or as shared parameters.

Resultset: Shared Callback Parameters (optional)

Table count: repeated zero or one time
Row count: exactly one row
Columns
BeginSharedParams mandatory any

This marker-column must contain NULL, and specifies that the columns following it will be passed as parameters to all subsequent calls to the component's stored procedure.

xxx optional any

This value will be passed back to the procedure as a parameter with the same name as its column.

Resultset: Actions (optional)

Additional actions to enqueue.

Table count: repeated zero or more times
Row count: zero or more rows
Columns
Action mandatory string

The name of the action. This will be returned to the stored procedure in the @Action parameter.

LinkAlias optional string

The alias of a link of type forward link. The link's target menu item will be executed by the Coordinator.

Omit or return NULL to trigger a call the Coordinator's procedure directly without calling a menu item first.

StopOnError optional bit

Set to 0 to have the Coordinator make the Store Error call if this menu item raises an error. The default is 1.

BeginPassingFields optional string

This marker-column must contain NULL, and specifies that the columns following it can be referenced by the forward link.

BeginExtraParams optional string

This marker-column must contain NULL, and specifies that the columns following it will be passed to the Coordinator procedure in its callback call.

Resultset: Forwarding (optional)

If forwarding is returned it must be the only table. Returning forwarding will terminate the Coordinator.

Table count: repeated zero or one time
Row count: zero or one row
Columns
ADMIN_ErrorMessage optional string

Displays a user friendly error message to the user. This blocks any forwarding for the user.

ADMIN_InfoMessage optional string

Displays a user friendly info message to the user. When the user clicks OK the user is forwarded.

ADMIN_SuccessMessage optional string

Displays a user friendly success message to the user. When the user clicks OK the user is forwarded.

ADMIN_Dialog optional string

The dialog alias of a predefined dialog to show the user. Must be the first column in the result set table. Use multiple result set tables to combine with other forwarding.

Use the menu item "Admin > Dialogs" to register new dialogs or find aliases for existing ones.

<xxx> (for ADMIN_Dialog) optional any

Any column without special meaning in the result set with the first column ADMIN_Dialog will be used to make replacements of placeholders in the message and title text.

ADMIN_DebugInfo optional string

Additional information to show the developer when using ADMIN_Dialog.

<passing_field> optional string

Any column with no other specific meaning will be passed along to the menu item or link you are forwarding to.

ADMIN_CidStepsBack optional int

Number of steps in the page history to jump back after execution (the default being one step back). This value overrides any destination specified by the query string.

ADMIN_ReturnToMenuItem optional string

Jumps back to the menu item with this alias after execution. This value overrides any destination specified by the query string. If no prior menu item is found with the given alias, then an error is thrown.

ADMIN_Forward optional string

Displays a user friendly message and then forwards to the next menu item.

ADMIN_ForwardLink optional string

Alias of the link to forward to.

ADMIN_ForwardMenuGroup optional string

Alias of the menu group to show after execution (instead of former menu item). This value overrides any destination specified by the query string.

ADMIN_ForwardMenuItem optional string

Alias of the menu item to execute after execution (instead of former menu item). This value overrides any destination specified by the query string.

ADMIN_Message optional string

Displays a user friendly error message to the user.

ADMIN_PasteHtmlFromPopup optional string

Pastes HTML into an HTML editor. See ADMIN_SetFieldValueFromPopup.

ADMIN_SetFieldValueFromPopup optional string

Sets the value of the field specified in the menuitempopup call. Only select this column if menu item is opened in a popup.

ADMIN_ClosePopup optional bit

If this column is anything but NULL the popup will be closed. Only select this column if the menu item is opened in a popup.

Default: The default behavior is to step back inside the popup window and close it if there is nothing to step back to.
ADMIN_ClosePopupAndReloadOpener optional bit

If this column is anything but NULL the popup will be closed and the parent will be reloaded. Only select this column if the menu item is opened in a popup. Avoid using this feature if the opener is a newEdit as that may interrupt the user's ongoing input.

ADMIN_ClearHistory optional any

When the value is not NULL all navigation history is cleared and the user can't navigate back. This is only supported when forwarding to another menu item.

ADMIN_RefreshMenu optional bit

Will trigger a reload of the sidebar if the column is anything but NULL.

Cache optional string

Cache key to be cleared. Supports wildcards.

CacheUserId optional string

Either a user id or '%'.

Clears all caches (e.g. access permissions) related to the specified user id.

Use '%' to clear caches for all users.

OkButtonText optional string

Changes the text of the OK button when used with ADMIN_ErrorMessage, ADMIN_ConfirmWarning, ADMIN_ConfirmQuestion, ADMIN_ConfirmDelete, ADMIN_InfoMessage, ADMIN_SuccessMessage, ADMIN_Message, ADMIN_Force, or ADMIN_Forward. ADMIN_Force,

SQL Call: Finished (mandatory)

This call is made when all enqueued actions have been executed, unless a previous action has already terminated the coordinator.

May modify database: Yes

Parameters

@Action string
Set to 'Finished'.

Resultset: Forwarding (optional)

Table count: repeated zero or more times
Row count: zero or more rows
Columns
ADMIN_ErrorMessage optional string

Displays a user friendly error message to the user. This blocks any forwarding for the user.

ADMIN_InfoMessage optional string

Displays a user friendly info message to the user. When the user clicks OK the user is forwarded.

ADMIN_SuccessMessage optional string

Displays a user friendly success message to the user. When the user clicks OK the user is forwarded.

ADMIN_Dialog optional string

The dialog alias of a predefined dialog to show the user. Must be the first column in the result set table. Use multiple result set tables to combine with other forwarding.

Use the menu item "Admin > Dialogs" to register new dialogs or find aliases for existing ones.

<xxx> (for ADMIN_Dialog) optional any

Any column without special meaning in the result set with the first column ADMIN_Dialog will be used to make replacements of placeholders in the message and title text.

ADMIN_DebugInfo optional string

Additional information to show the developer when using ADMIN_Dialog.

<passing_field> optional string

Any column with no other specific meaning will be passed along to the menu item or link you are forwarding to.

ADMIN_CidStepsBack optional int

Number of steps in the page history to jump back after execution (the default being one step back). This value overrides any destination specified by the query string.

ADMIN_ReturnToMenuItem optional string

Jumps back to the menu item with this alias after execution. This value overrides any destination specified by the query string. If no prior menu item is found with the given alias, then an error is thrown.

ADMIN_Forward optional string

Displays a user friendly message and then forwards to the next menu item.

ADMIN_ForwardLink optional string

Alias of the link to forward to.

ADMIN_ForwardMenuGroup optional string

Alias of the menu group to show after execution (instead of former menu item). This value overrides any destination specified by the query string.

ADMIN_ForwardMenuItem optional string

Alias of the menu item to execute after execution (instead of former menu item). This value overrides any destination specified by the query string.

ADMIN_Message optional string

Displays a user friendly error message to the user.

ADMIN_PasteHtmlFromPopup optional string

Pastes HTML into an HTML editor. See ADMIN_SetFieldValueFromPopup.

ADMIN_SetFieldValueFromPopup optional string

Sets the value of the field specified in the menuitempopup call. Only select this column if menu item is opened in a popup.

ADMIN_ClosePopup optional bit

If this column is anything but NULL the popup will be closed. Only select this column if the menu item is opened in a popup.

Default: The default behavior is to step back inside the popup window and close it if there is nothing to step back to.
ADMIN_ClosePopupAndReloadOpener optional bit

If this column is anything but NULL the popup will be closed and the parent will be reloaded. Only select this column if the menu item is opened in a popup. Avoid using this feature if the opener is a newEdit as that may interrupt the user's ongoing input.

ADMIN_Unselect optional bit
Alias for ADMIN_UnselectAll.
ADMIN_UnselectAll optional bit
If this column is anything but NULL all items are removed from the list of selected items.
Default: By default selected items are maintained when you return to the grid/calendar. This applies even if the selected item is no longer visible in the component unless this column is specified.
ADMIN_ClearHistory optional any

When the value is not NULL all navigation history is cleared and the user can't navigate back. This is only supported when forwarding to another menu item.

ADMIN_RefreshMenu optional bit

Will trigger a reload of the sidebar if the column is anything but NULL.

Cache optional string

Cache key to be cleared. Supports wildcards.

CacheUserId optional string

Either a user id or '%'.

Clears all caches (e.g. access permissions) related to the specified user id.

Use '%' to clear caches for all users.

OkButtonText optional string

Changes the text of the OK button when used with ADMIN_ErrorMessage, ADMIN_ConfirmWarning, ADMIN_ConfirmQuestion, ADMIN_ConfirmDelete, ADMIN_InfoMessage, ADMIN_SuccessMessage, ADMIN_Message, ADMIN_Force, or ADMIN_Forward. ADMIN_Force,

SQL Call: Validate parameters

Allows you to validate the SQL parameters before any other SQL is run in the component. This call is only made if the SQL is a stored procedure and Validate parameters is checked.

May modify database: No

Parameters

@Force bit
Set to 1 if the last call to validate parameters used admin_force and the user clicked OK in the OK/Cancel dialog.
@ValidateParams bit
Set to 1 when this call is made.

Resultset: Messages (optional)

Table count: repeated zero or one time
Row count: zero or one row
Columns
ADMIN_ErrorMessage optional string

Message explaining why the parameters are rejected.

ADMIN_Force optional string
Message asking the end user to confirm their parameters.
ADMIN_Message optional string
Message explaining why the parameters are rejected.

Custom access control and logging

SQL Call: Custom access control and logging

Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.

Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.

The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.

If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.

May modify database: Yes

Resultset: Access permissions

Return whether the user is allowed to visit the menu item with the current parameters.
Table count: repeated exactly once
Row count: exactly one row
Columns
GrantAccess mandatory bit
1 if the user is allowed to view the menu item, 0 if the user should not be allowed to view the menu item.

If 0 then an error will be logged as the user should not have been able to reach the menu item with the given parameters in the first place.

Examples

Maintaining a Batch ID

Batch IDs are useful for correlating all processing done by a coordinator, especially for logging purposes.

Any column in the Shared Callback Parameters table will be passed to the procedure in all subsequent calls, including the Finished call. You can create a batch ID in the Init call, and make it a shared callback parameter.

CREATE OR ALTER PROCEDURE dbo.CoordinatorWithBatchId
	@Action varchar(50),

	-- Shared parameters, passed to all calls
	@BatchId uniqueidentifier = NULL,

	-- Parameters for DoX call
	@XId int = NULL,

	-- Parameters for DoY call
	@YId int = NULL
AS
BEGIN
	IF @Action = 'Init'
	BEGIN
		SELECT
			NULL AS BeginSharedParams,
			NEWID() AS BatchId;

		SELECT
			'DoX' AS Action,
			NULL AS BeginExtraParams,
			1 AS XId;

		SELECT
			'DoY' AS Action,
			NULL AS BeginExtraParams,
			99 AS YId;
				
		RETURN;
	END;
END;

Post-Processing After a Variable Amount of Actions

For most workflows, you would do post-processing in the Finished call. In some workflows, however, you may need to perform post-processing before the batch has fully completed.

The coordinator supports this by allowing you to invoke callbacks directly, even when no menu item is being executed. This makes it possible to process the results of an initial sequence of menu items, use that intermediate output to influence subsequent menu items, and then allow the coordinator to eventually reach the standard finished callback for final processing.

CREATE OR ALTER PROCEDURE dbo.ImportDocuments_Coordinator
	@Action varchar(50)
AS
BEGIN
	-- Example tables
	CREATE TABLE #DocumentBinaryData
	(
		DocumentId int PRIMARY KEY,
		Document varbinary(MAX) NOT NULL,
		DocumentFilename nvarchar(300) NOT NULL
	);

	CREATE TABLE #DocumentTextData
	(
		DocumentId int PRIMARY KEY,
		DocumentText nvarchar(MAX) NOT NULL
	);

	-- Process actions

	IF @Action = 'Init'
	BEGIN
		-- Import documents.
		SELECT
			'ImportDocument' AS Action,
			'ImportExcel' AS LinkAlias,
			NULL AS BeginPassingFields,
			DocumentId
		FROM
			#DocumentBinaryData
		WHERE
			DocumentFilename LIKE '%.xlsx';

		SELECT
			'ImportDocument' AS Action,
			'ImportPdf' AS LinkAlias,
			NULL AS BeginPassingFields,
			DocumentId
		FROM
			#DocumentBinaryData
		WHERE
			DocumentFilename LIKE '%.pdf';

		-- Enqueue action executed once documents are imported
		SELECT
			'AllDocumentsImported' AS Action;

		RETURN;
	END;

	IF @Action = 'AllDocumentsImported'
	BEGIN
		-- Pre-process documents
		/* EXEC PreProcessMyDocuments */

		-- Create embeddings from documents
		SELECT
			'ComputeEmbedding' AS Action,
			'ComputeEmbedding' AS LinkAlias,
			NULL AS BeginPassingFields,
			DocumentId
		FROM
			#DocumentTextData;

		RETURN;
	END;

	IF @Action = 'Finished'
	BEGIN
		-- Post-process embeddings
		/* EXEC PostProcessMyDocuments */

		SELECT
			'All done!' AS ADMIN_SuccessMessage;
	END;
END;