Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Dynamic Data Manager node lets you manage the data that you want to store.

You have the following options:

Model

You can choose the schema from this drop-down.

Action

Choose an action from the drop-down that you want to perform on the schema.

Read

Based on the parameters given in the payload, the Dynamic Data Manager node will fetch the data.

In the previous image, the Dynamic Data Manager node will fetch all the data items from the Project.

  • limit” specifies the number of data items to be shown per page in the result object. The maximum value is 999. Always specify a limit. If you do not specify a limit and there are more than 999 results, it will return invalid number of results.

  • page” is the page number to be shown in the results object. The first page starts at 1.

  • sortBy” is used to sort the fetched data based on the criteria.
    For example, {"sortBy":{"modifiedAt":-1}} will sort the data items shown in the result array based on the modified date displaying the latest modified data item first.

The following image shows the result payload.

You can identify a data item using the ID or the Item Name. You can use either of them to get the data item in the Dynamic Data Manager node.

The ID is unique for a data item. You will get only one result when you use the correct ID.

Item Name is asked while creating the Data item manually. Multiple data items can have the same item name. You can query the data using the item name.

Example Read: How to read with Paging, Greater than, AND

Return all the values who are version, 1, and the createdAt date was greater than 20 days, whose page number equals the value passed to the data manager.

If there are more than 999 items we need to concatenate the results.

Because we are doing a loop to get all the pages of data, it is a good idea while testing to add a delay to throttle the number of queries requests, in case you make a mistake and created an infinite loop. Then either change the delay to 1 ms, or remove the delay completely.

The Dynamic Data Manager mode is set to Read.
AND condition of version, CreatedAt, Page
limit says for this page do not bring back more than 999 items. Which is the max limit.

Ignore the red X in this example, the validation is confused by the mustache tag, msg.pagePnter is a number. sortBy, in this case we used createdAt. createdAt & modifiedAt & _id are always returned in the collection.

{
  "version": "1",
  "createdAt": { "$gt" : "{{msg.startDate}}" },
  "limit": 999,
  "page": {{msg.pagePntr}},
  "sortBy": {"createdAt":-1}
} 

The init function node sets up the pagePntr to start at 1. A common mistake is to start at 0.
Also setting up the array to store the results, in this case msg.userDataArray = [ ]

msg.pagePntr = 1;  // init page pointer to 1
msg.userDataArray = [];  // init aray
var moment = global.get('moment');
const now = moment();  // use moment to creat time 20 days earlier than today
const DaysAgo = now.subtract(20, "days").startOf("day").utc().toISOString();
node.warn(DaysAgo);  // "2020-11-16T00:00:00.000Z"
msg.startDate = DaysAgo;
return msg;

The loop function node concatenates the results of each page, until it collects all the data.

var userData = msg.data.dynamicData.result;  // Get the results from dynamic data node.
if (userData.length > 0) {   // is there any data.
    msg.userDataArray = msg.userDataArray.concat(userData);  // append to the last array.
    msg.pagePntr = parseInt(msg.pagePntr) + 1;  // increment the page pointer.
    node.warn('Next page ' + msg.pagePntr);
    if(msg.data.dynamicData.paging.hasMore.hasNext === false) {   // is there another page. if not exit loop
       return [null,msg]    
    } else {
        return [msg,null]  // get the next page of data.
    }
} else {
    return [null,msg]   // no data
}

Example Read, OR condition, AND, NOT Equal

{
"$or": [{"runStatus": "start"}, {"acknowledge": "yes"}],    
  "runStatus": { "$ne": "Complete" },
"limit": 900,
"page": 1,
"sortBy": {"createdAt":-1}
} 

Create

Lets you create a new data item. If you don’t specify a project ID in the payload, the data is created as Global data.

As shown in the following image, the payload may contain hard-coded values or mustache tags. Data in the mustache tag is converted to a string while saving the data.

To avoid encoded or Unicode characters getting saved, place an ampersand (&) in the mustache tag.

Creating multiple data items

You can create multiple data items at the same time in two ways.

  1. Place multiple objects in an array. In the following image, an array with two data items is given in the payload of the Dynamic Data Manager node.

  2. Create an array in the function node placed before the Dynamic Data Manager node. The following code lets you create a sample array and store it in msg.payload.data.

var _ = global.get('lodash');
var sample = [
               {
                 SampleText : "Google",
                 SampleURL  : "https://www.google.com/"
               },
               {
                 SampleText : "Amazon",
                 SampleURL  : 'https://www.amazon.com/'
               }
             ];
_.set(msg,'payload.data',sample);

When using this method to create multiple data items, the payload in the Dynamic Data Manager node should be left empty.

Update

If the field is available in the schema, the content of that field will be updated with the content given in the payload. The _id is used to identify the data item (required). The field that you want to update must be inside the data object. For example, in the following image, hospitalCounty is a field available in the schema that will be updated with the data “county”.

Example 2

In this example user, each record has a unique id called a token, only one result will be returned and we are going to update the runStatus to Complete

Upsert

If multiple results are found for a query, the oldest data item gets updated.

Queries fields are available

If the queried fields are available, the schema fields are updated with the content given in the payload. In the following example, queried fields are available, but one of the payload properties is not available in the schema. NewField is not available in the schema. Except for NewField, all the other fields will be updated based on the payload.

Alternatively, you can create an array in the function node placed before the Dynamic Data Manager node to send the data to msg.payload.data.

var data = 
{
  "ids": [
        "221778457701379939"
    ],
    "221778457701379939": {
        "q": "<p><img alt=\"\" height=\"380px\" src=\"https://s3.amazonaws.com/orbitahealth/clients/adira-prod/assets/dynamic/images/806417701b38147f0-94e4-11ea-a6f4-fbb89749aa9b15a8209f0-bc62-11ea-9309-83ecac418749.png\" width=\"380px\" /></p>\n\n<p>Hey there! I’m Wanda from New York.</p>\n<hr/><p>If you’re pregnant, have a baby, or have a little one up to 5 years old, WIC is here to support you!</p>\n<hr/><p>Citizenship and immigration status doesn’t matter, and, of course, this discussion is private.</p>\n<hr/><p>I’m here to make your life a little easier. Click Start if you’re cool with the <a href=\"https://www.adirallc.com/privacy-policy.html\" onclick=\"window.open(this.href, '', 'resizable=yes,status=no,location=no,toolbar=no,menubar=no,fullscreen=no,scrollbars=no,dependent=no,width=500,left=100,height=500,top=100'); return false;\">Terms and Privacy Policy!</a></p>\n",
        "question": "<img height=\"380px\" src=\"https://s3.amazonaws.com/orbitahealth/clients/adira-prod/assets/dynamic/images/806417701b38147f0-94e4-11ea-a6f4-fbb89749aa9b15a8209f0-bc62-11ea-9309-83ecac418749.png\" width=\"380px\" /><br />  Hey there! I’m Wanda from New York.<br /> If you’re pregnant, have a baby, or have a little one up to 5 years old, WIC is here to support you!<br /> Citizenship and immigration status doesn’t matter, and, of course, this discussion is private.<br /> I’m here to make your life a little easier. Click Start if you’re cool with the Terms and Privacy Policy!<br /> ",
        "startTime": "2020-07-03T09:21:18.531Z",
        "endTime": "2020-07-03T09:21:34.216Z",
        "answer": "Start"
    }
}
msg.payload.data = 
{
    "jsonfield_schemakey": data
};
return msg;

When using this method to create multiple data items, the payload in the Dynamic Data Manager node should be left empty.

Queried fields are not available

If the queried fields are not available, it creates a data item and update the available fields in the schema based on the payload. For example, the following image shows the Newquery is not available as a field in the schema. Therefore, a new data item with a new id will be created with the payload.

Delete

You can Delete the data using a query. If the query matches multiple Data items, each of them is deleted.

Payload

A Function node should be placed prior to the Dynamic Data Manager node to verify the mandatory fields of the schema (model). These schema fields will be saved/queried based on the details given in this payload field of the Dynamic Data Manager node.

The output for the Dynamic Data Manager node will be in the msg.data object.

Related Articles

  • No labels