Using OData to transfer data between runtimes

So, you’ve been building a nice application and testing it in the Staging Runtime. While doing so, you’ve entered quite some useful data. When it’s time to go Live, you publish and start the Live Runtime of your application. Alas… no data! You will need to re-enter everything… Or maybe not?!

With the support for OData, both consuming and exposing, WEM makes it quite easy to transfer data from one runtime to another for your project. This is particularly useful in two cases:

  1. When you go live with your application and want to re-use data which is already available in Staging;

  2. When your application has been running Live for some time, containing lots of useful data and you want to get it available in Staging for testing new or changed features or investigate bugs.

So, how do you get this working? Let’s work out number 1:

Getting data from Staging to Live

Create the OData Exposure:

  1. Go to the Security Panel on the Project Settings page;

  2. Create an OData Login and give it Full Access (or determine which access is really necessary);

  3. Publish to Staging, this will enable OData access on the Staging runtime database;

Import the OData Service

  1. Go to Webservices Tab in the Project tree, access the context menu on [Remote data sources] and click [Import OData Service];

  2. Enter the OData Service information:

    • Enter a name for this service (like MyProjectStagingData);

    • Use the portal’s Staging URL, and append /odata/, e.g.: https://portalname.staging.wem.io/odata/;

    • Enter the credentials of the OData Login created in previous step;

    • Hit Import and see the lists and fields appear in the tree...

Then, build flowcharts

Using the remote data source (in this case, your Project Staging Runtime data), the database lists are available directly from your Project Tree (Remote Data Sources) and you can use them the same way as you use the database lists in your Data Model with listnodes on flowcharts, datagrids and repeaters on Templates.

You can drop a Datagrid on a template based on any of the lists in the Remote Data Source just to display the data. You can put a loopnode on such a list and copy the data to the corresponding list in your Data Model (add new row and handle each corresponding field with each iteration of this loop). Run it in preview mode to get the Staging data into Preview.

Be careful, use filters and checks where necessary!

Check if you are in the correct runtime, by using the IsLive() or IsStaging() functions (you don’t want to accidentally copy staging data into staging again…); Check if an item already exists, if you are going to use this flowchart repeatedly; Do not use the ID-fields, as they are automatically generated so they might (and probably will) be different between the Staging and Live runtimes.

Mind the Concepts! When copying staging concept fields to live concept fields, the underlying technical information is not exactly the same. Using an Assignment Node on a Live.DataModel.ConceptField and plainly assigning it with the ExternalDataSource.StagingData.DataModel.ConceptField will just not work as you might expect. But it’s easy to map it correctly with the available Ontology-functions.

For a Single Select field, use something like:

first(concept of GetChildren(‘root concept of single select’) 
where tostring(concept) = tostring(ExternalDataSource...SingleSelectField))

as the expression in the assignment node (replace the fields and concepts with the correct information).

For a Multi Select field, use something like:

GetDescendants(‘root concept of multi select’)
where tostring(concept) 
	in (tostring(concept) of ExternalDataSource...MultiSelectField)

This approach using OData to transfer data from Staging to Live is just an example.

Other options are using Export/Import nodes with json or xml forms.

Last updated