Skip to main content
Version: 10.2.8

Define allowed Data Store queries

By default, WorkFusion security blocks all Data Store (DS) API calls from Manual Tasks, except Allowed Data Store Queries. Therefore, if you develop a custom Manual Task that uses DS API calls from JavaScript, you must create such allowed queries.

Create Allowed Data Store Query

To create an Allowed DS Query, follow the steps below:

  1. Open the Manual Task that uses DS API calls and navigate the Design tab.

  2. Switch the Code Editor mode.

  3. Click the Allowed Data Store Queries button.

    A grid with DS Queries appears on the screen:

  4. Click the Create Query button or click an existing query name.

  5. In the displayed popup, add parameters for your DS Query:

    1. Enter a unique Name.
    2. Select an existing Data Store. You can click the eye icon to open the selected DS in a new browser tab.
    3. Enter a valid Query.
    4. Click the Save button.

Allowed queries do not have to return anything. However, you can use OUTPUT to return data. Below is a query example:

INSERT INTO @this (ID, document)
OUTPUT Inserted.ID
VALUES (:id, : document);

Use Allowed DS Query in Manual Task code

The Data Store API call has the following URL pattern:

/workfusion/public/v2/datastores/executeNamedQuery?queryName=demo&nativeId=hitId&parameters={status:"COMPLETED"}

Where:

  • queryName is the name of your Allowed DS Query.

  • nativeId is hitId of the task.

  • parameters is a JSON representation of an object containing dynamic query parameters.

To allow using DS queries, add the following JavaScript code snippet at the bottom of your Manual Task code:

<script type="text/javascript">
var hitId= $("input[name=hitId]").val();
$.ajax({
dataType: "json",
type: "get",
url: "/workfusion/public/v2/datastores/executeNamedQuery",
data: {
queryName: 'demo',
nativeId: hitId,
parameters: JSON.stringify({
status: "COMPLETED",
})
},
success: function (resp) { console.log(resp); },
error: function (resp) { console.log("error", resp); }
})
</script>

You can access the result of the AJAX request only using one of the following methods:

  • Task Preview > External URL: the link appears for the tasks that are not in the Draft state, meaning they should already be run.
  • In Workspace, when you accepted the respective task.
troubleshooting

For troubleshooting tips, refer to the following support guides: