Text to Reference - liquid

Case

Assuming the content being synced has a text field that references a content at the destination. We want to take the text field, match it to a content, and create a relationship field at the destination system to that content.

In this example we have a file with a bit of text that has the name of a ship. This ship is already a content in the destination system and we want to sync this file with a relationship field to that existing ship content.

We need to be able to

  1. Get the existing ship content ID

  2. Set the ship content ID in the synced content

Solution

ImpulseSync can solve this with a couple jobs using the store-field and liquid-field (using getStoredValue filter) manipulators.

Configure pre-requisite job

First we will configure a pre-requisite job. This job will pickup the ship contents and store their IDs with the key being the name of the ship.

Because this job will not deliver content and only store content it does not need a destination endpoint.

The job will have a store-field manipulator configured to store the content ID in a key value pair where the key is the name of the ship and the value is the content ID.

The optional parameters Storekey and Storevalue are used to create the key and value pair to be stored. These config paramters use liquid templates to build the key and value.

Configure primary job

Once the pre-req job is configured we can then configure the primary job to make use of the stored values.

This primary job will make use of a liquid-field manipulator to retrive the stored content ID and set it into a Motation relationship field to be synced.

Because the source content is a file, we make use of the section filter to parse out the ship name exact ship name to be referenced. Other systems may simply have the name of the ship directly in a field and not need any additional parsing.

Once we have the name of the ship, we use the getStoredValue filter to retrieve a stored value based on the passed in key. In this case the passed in key is a variable called storeKey which has the value of the ship name. So we will get the stored value (content ID) for the passed in ship name.

Because we are creating a relationship field, we will also need to use the Impulsefieldvalue config option with the value ImpulseValue . This tells the manipulator to create a specific Impulse value field, rather than set the value to a default field. More details can be found in the liquid doc.

Configure storage/pipeline

Because we're using the store-field manipulator to store data and in another job attempting to retrieve that stored data, we need to be able to store the data across jobs. Certain plans allow for data to be stored permanently. If you have that plan and want to store the data permanently, you will need to set the Storecontent job option on the endpoints for these jobs that will store and retrieve the data.

If you want to temporarily store the data for the length of these jobs, you must set them together in a pipeline. Jobs in a pipeline make use of the same temporary storage, allowing for jobs to store and retrieve data between each other in the same pipeline. All stored data in a pipeline will be deleted once the pipeline is finished.

Once the storage option is configured, run the jobs/pipeline and view the synced content.

Array of relationships

The same solution can be expanded for an array of relationships as well.

First, create a pre-req job using the same or simillar config.

Then in the primary job, the liquid template could look something like this.

Notice the additional logic to iterate through an array of text values, and properly create a Motation Relationship field object to be synced. (i.e., watch for comma placements, empty values, etc.)

And at the destination you have a relationship/reference field with multiple related content.

Last updated