Many-to-one mapping
It is possible to implement many-to-one mapping for your Embedded solutions.
For example, you may wish 'Country' in one service to be mapped to 'Region' in another:
Service one key | Service one values | Service two key | Service two value |
---|---|---|---|
Country | US, Canada | Region | North America |
UK, Germany, France, Italy | EU | ||
India, Pakistan, Sri Lanka | South Asia |
Or you may wish 'Status' in one service to be mapped to 'Availability' in another:
Service one key | Service one values | Service two key | Service two value |
---|---|---|---|
Status | available, part-time | Availability | available for work |
unavailable, full-time, sick-leave | unavailable for work |
Note that in both these cases:
Key mapping is one-to-one
Value mapping is many-to-one
Many-to-one exampleCopy
The below example puts the second table above into practice.
It imagines a scenario whereby a solution is triggered by a webhook coming from a service which alerts requests for work availability - including the name and status of the individual in question:
The main steps here are:
The webhook is received
The JSON data is parsed with an Object Helpers step (optional - only if the formatting of the json needs it)
A script is set up to map the Keys
A script is set up to map the Values
The mapped information is then sent to be processed into the second service (here it is done by sending to a callable workflow set up for sub-processing)
Trigger Event Reply is used to reply to the original service and indicate that the request has been successfully received (optional)
1 - Receive and parse webhook dataCopy
First of all we have set up an Object Helpers step to Parse the JSON coming from the webhook:
2 - Create the 'Map keys' scriptCopy
Then we configure the Map keys script:
Note that this has two inputs:
keyDataMappings which uses the config value
$.config.keyDataMapppings
(this is the config that is made available for the End User to set the mappings in the Config Wizard)webHookFields which pulls the parsed json fields from the webhook using
$.steps.object-helpers-1
From the debug output above you will see that the purpose of this is to map the keys of the fields from name and status to Name and Availability.
The script itself is a standard mapping script:
1exports.step = function (input) {2// The mappings that will eventually be added by your end user:3var mapping = input.keyDataMappings;4// The new object we will use to create an entity to insert:5var newEntity = {};6for (var field in mapping) {7newEntity[mapping[field]] = input.webhookFields[field];8}9return newEntity;10};
3 - Create the 'Map values' scriptCopy
Then we configure the Map values script:
Note that this has two inputs:
valueDataMappings which uses the config value
$.config.valueDataMapppings
(this is the config that is made available for the End User to set the mappings in the Config Wizard)mappedFields which pulls the result from the first script using
$.steps.script-1.result
From the debug output above you will see that the purpose of this is to map the values of the fields. In this case it maps part-time to available for work.
It is key to note here that the values mapping script is slightly different:
1exports.step = function (input) {2// The mappings that will eventually be added by your end user:3var mapping = input.valueDataMappings;4// The new object we will use to create an entity to insert:5var newEntity = {};6for (var field in input.mappedFields) {7var currentValue = input.mappedFields[field];8newEntity[field] = mapping[currentValue] || currentValue;9}10return newEntity;11};
4 - Send the mapped result for processingCopy
The mapped result can then be sent for processing using $.steps.script-2.result
5 - Set up the available mappings in the Solution EditorCopy
keyDataMappingsCopy
In the Solution Editor we can set the mappings for keyDataMappings:
Note that this is not set as 'Many-to-one':
service-1Copy
service-2Copy
Default mappingCopy
valueDataMappingsCopy
And then we can set it up for valueDataMappings
Click through the tabs to see the setup for each service and the default setting.
Note that this is set as 'Many-to-one':