JavaScript Popping - Queued

If the order in which a series of activities are completed is important, then the activities should be queued. When queued, each Workflow and activity will only be created as it reaches the front of the queue, so there is no other in-progress Activity that can be switched to by the agent as there is with immediate popping.
Unlike a URL pop or immediate JavaScript pop, the current activity and all Workflows queued within it will be completed before any new activity is then popped. For example, this could be used to queue a payment or survey Workflow within the current activity for completion once the current Workflow is completed, and then queue a subsequent activity for a new record once the Workflows relating to the current activity have been completed.
Important: This article covers two near-identical functions. However, it should be noted that the Desktop.Queue.QueueCampaignByName() function is intended for use by a plugin rather than in a Workflow run, and cannot be used from within a Workflow run as other Helper Functions can be. It is documented here for completeness, but this article will focus primarily on the use of Script.Queue.QueueCampaignByName() instead, which can be used from within a Workflow run.

How To

The syntax for queueing via JavaScript is:
Script.Queue.QueueCampaignByName(newActivity, identifier, reference, restartScript, data, connector, connectorType);
Desktop.Queue.QueueCampaignByName(true, identifier, reference, restartScript, data, connector, connectorType);
The available parameters for both functions are:
Specifies whether to start a new activity for the requested Workflow pop or utilise the current activity.
Note: for Desktop.Queue.QueueCampaignByName(), this is always true.
If true, this will wait until the current activity has finished and all Workflows have exited before launching the Workflow in a new activity (queuing).
If false, the Workflow will be launched in to the current activity once the currently queued Workflows in the current activity are exited.
The identifier of the Campaign or Campaign Alias to launch, this could be a Scripting campaign, a dialler list, or a SQL table.
The reference of an existing record to launch. If a record with this reference does not exist, a new record will be created. If null or an empty string is passed, an automatically-generated reference of the form CSAUTO-#-#-# will be used for the new record. This will be the value of [var_csReference] in the popped Workflow.
If set to true, the Workflow will start on the Start Page. If set to false and an existing reference is passed, the Workflow will pop on the page reached in the previous Workflow run. This is only typically set to false to carry on incomplete Workflow runs, and the Workflow must have been left without reaching the Last Page (for instance, via the Script.Finish() helper function) for this to work properly.
If set to null or an empty string, the default behaviour of true is used.
If using Integration - Generic, then a JavaScript object containing data can be passed through to the queued Workflow run, which will map the values of any keys that match Workflow Variables or mapped fields. This will also be available through the Script.Data helper functions.
If no data is required, null or an empty object can be passed in.
Specifies the connector_id that will be written to tbl_outbound_history for the record. This will be the value of [var_csConnectorID] in the popped Workflow.
Specifies the connector_type that will be written to tbl_outbound_history for the record. This will be the value of [var_csConnectorType] in the popped Workflow.
Example for SQL Plugin:
Script.Queue.QueueCampaignByName(true, "tbl_CustomerData", "4074", true);
Script.Queue.QueueCampaignByName(true, "GenericCampaign", null, true, {
    var_csCallerName: "Joe Bloggs",
    DaytimeNumber: "01234 567890"
This then queues our Workflow, and will populate the values "Joe Bloggs" and "01234 567890" into [var_csCallerName] and the linked Workflow field of the queued Workflow.


If the function is being invoked from an external website that Scripting is running within, and the external website and Scripting are on different domains, then domain spoofing will need to be utilised to allow this to work.
Upon exiting all JavaScript-queued Workflows, the agent will be returned to the Desktop.