Using OData to transfer data between runtimes
Last updated
Last updated
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:
When you go live with your application and want to re-use data which is already available in Staging;
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:
Go to the Security Panel on the Project Settings page;
Create an OData Login and give it Full Access (or determine which access is really necessary);
Publish to Staging, this will enable OData access on the Staging runtime database;
Go to Webservices Tab in the Project tree, access the context menu on [Remote data sources] and click [Import OData Service];
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...
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.
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:
as the expression in the assignment node (replace the fields and concepts with the correct information).
For a Multi Select field, use something like:
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.