WRITE TO MULTIPLE DATA STORE ENTITIES

BASIC SETUP - WRITE ROWS TO TWO OR MORE TABLES AT ONCE

Prerequisites:

  • You have created Data Types for all tables you intend to write to, and they are saved in your application's Data Store (as Data Store Entities).

  • You have created constants (of "Data Store Entity" Type) that point to the Data Store Entities you are writing to/with.


For this node, you only need to configure the Inputs tab. Double clicking on the node, click Data > Inputs > Value To Store > Blue Edit Icon (pencil):

In the popup Expression Editor, write an expression such as:

{

{entity: cons!APP_DSE_TIMESHEET_LOG, data: {pv!timesheet_log_data}},

{entity: cons!APP_DSE_SUBMISSION_STATUS, data: {id: NULL, status: "Complete"}},

{entity: cons!APP_DSE_EMPLOYEE_EVENTS, data: {{id: NULL, event: "Submission 1", time: now()},{id: NULL, event: "Submission 2", time: now()}}}

}

You will have one "{entity: X, data: Y}" item in your dictionary per Data Store Entity.

  • Under "entity", add the constant that points to the Data Store Entity that you intend to write to.

  • Under "data", add the data to write to the entity, which can be, for example:

    • A process variable of the correct type (matching the constant referenced in the corresponding "entity")

    • A dictionary with the data

Some additional points:

  • You can do the same thing as "Write to Multiple Data Store Entities" using the standard single "Write to Data Store Entity" Smart Service and an AND gate that activates various "Write to Data Store Entity" nodes at once, the difference is that the "Write to Multiple Data Store Entities" will undo/revert the writes to the database if any particular one fails - so it may give you peace of mind knowing that we did not have a partial write to some tables but not others.

  • If you enter NULL for an auto-increment field (in many cases, this is the ID), for this Smart Service or for the standard single "Write to Data Store Entity" Smart Service, it will generate the ID automatically while writing to the database.

  • You can write multiple rows to each table, as was done above for this entry: {entity: cons!APP_DSE_EMPLOYEE_EVENTS, data: {{id: NULL, event: "Submission 1", time: now()},{id: NULL, event: "Submission 2", time: now()}}}. (To do this with a process variable, just ensure the variable is set to "Multiple" in your process model under File > Properties > Variables, or it may only write the first row to the database.)

RETRIEVE SAVED TABLE DATA BACK INTO A PROCESS VARIABLE

To get the newly-created table row IDs of the saved data, you can use the Save Into parameter. You can click on the +V icon to quickly get a process variable of the correct type:

Once you have created the process variable as shown above (which will create a process variable of "Entity Data" type, named, for example, ValueToStore), you can access the sub-elements of this variable, using an expression such as: pv!StoredValues[3].data[1].id (which, using the example from above, would return the id of the first row saved). Or, for example, you could try: pv!StoredValues[3].data[2].event, which would return "Submission 2".