Using ConnectIds for Tasks (Actions)

Running a task script with its own Connect IDs

When you associate a task with a dataset, that task will be configured by default to run with the same set of Connect IDs that were used to retrieve that dataset. This makes it easy for tasks to work with the right Connect IDs when run in the context of a dataset you are viewing, while allowing them to use their own Connect IDs when run independently; however, there are scenarios where you may want a task to run in the context of its own Connect IDs, even when it is run in the context of a dataset you are viewing. For example, if you are viewing a collection of users gathered from Microsoft 365, and you have a task that adds the selected users to a SharePoint group, that script really only needs a Connect ID that allows it to connect to SharePoint Online so that it can invoke the appropriate SharePoint Online command. It doesn’t need the Connect ID that was used to retrieve the user record from Microsoft Azure. Since the task does not need the Connect IDs that were used to retrieve the dataset, when you assign the task to the dataset, you can check the **Allow task to run with own Connect IDs** checkbox. Checking this checkbox instructs Cloudbridge to only use the Connect IDs associated with the task script when running that script.

Another scenario where this feature can come in handy is when you have some scripts that you want run in the cloud, and others that need to run in an on-premises proxy. Checking the Allow task to run with own Connect IDs checkbox allows you to ensure that the task can be run on a proxy, even if the script that gathered the dataset you are viewing was run in the cloud.

What if you need the both the Connect IDs associated with the selected rows in a dataset and the Connect IDs configured for a task script?

In more complex scenarios, you might need both the Connect IDs that are associated with selected rows in a dataset (which are stored by name in the ConnectIds column) as well as additional Connect IDs that are only necessary for a specific task or a set of tasks. If you add a `$ViewConnectIDs` parameter to the end of your `param` block in your task script, Cloudbridge will pass a collection of Connect IDs into the `$ViewConnectIDs` parameter. This collection is an array of strings, where each string contains the name of the Connect ID associated with the relative row that was selected in the grid when the task was run.

For example, if you select 3 rows in your grid, and then invoke a task that is configured with the **Allow task to run with own Connect IDs** option, and within your task script your param statement includes a `$ViewConnectIDs` parameter, then that parameter will contain an array of 3 strings, with the first string matching the name of the Connect ID associated with the first row in the grid, the second string matching the name of the Connect ID associated with the second row in the grid, and the third string matching the name of the Connect ID associated with the third row in the grid. This allows you to look up those Connect ID names in the built-in `$ConnectIDs` hashtable, so that you can then retrieve the credentials you need to run your task script as you process each of the rows that were selected when it was invoked.