App Connect users can now create reusable mappings in their flows by using the new Set Variable node.

You have always been able to use the JSONata query and transformation language to compose mappings for use in your flow. By adding the Set Variable node, you can specify any object structure and set mappings on that object’s properties. Those mappings are then available for use in subsequent nodes, giving you the power of “write-once, use many” for any mapping expression.

The new Set Variable node is available from the Toolbox tab:

Let’s see the benefit of using the Set Variable node through an example use-case.

An event management scenario

I have an Eventbrite account that I use to manage many events for my company called “MattClarkeEventsInc“.
Each time I receive a new attendee to one of these events, I want to be able to respond in the following way:

  • Respond by email to the new attendee, providing them with information on other attendees from their company.
  • For each of those discovered existing attendees, send an email to notify them of the new attendee from their company.
  • Add information about the new attendee to a spreadsheet that I keep up to date with the known attendee list, indicating if the attendee is an employee of my company or not.

To be able to send the emails and keep the spreadsheet updated, I require the following information:

  • Attendee’s full name
  • Attendee email
  • Event name
  • If they are an employee of my company
  • The related list of attendees information – each colleague’s name and email

My event management flow

Upon receiving a new attendee, I gather the following information using existing Eventbrite retrieve actions:

  • The event itself (using the event ID of the new attendee)
  • All attendees to the event (using the same event ID of the new attendee)

With the Set Variable node, I can bring together all the information that I need into a readable data structure that can then be mapped to. I define the structure of my variable to be:

And then I use Edit mappings to define each property’s mapping, using JSONata expressions where appropriate:

The Attendee and Event information are fairly trivial mappings, the most complex being deriving if the attendee is my employee or not.

The FellowAttendees mapping is of type “Array of objects“, as I need it to be a list of attendee objects each with some information about them. That mapping needs to output an array that can be iterated over and have mappings applied on the child properties.

I need the contents of the FellowAttendees array to contain all current attendees who are also from the same company of the new attendee. I used the following JSONata expression to establish that list:

$EventbriteRetrieveattendees[profile.company=$Trigger.profile.company][profile.email != $Trigger.profile.email]

The predicate (the rules contained within the [ ] ) for the mapping will evaluate a list of attendees:

  • Whose company matches the company of the new attendee
  • But whose email is not that attendee – so that I don’t have the new attendee in that list

I can now use those mappings in my actions I want to perform in my flow.

So for the new attendee, I construct the email using my Set Variable node mappings:

Because I have the list of fellow attendees as an array structure I need to apply some logic that will allow me to extract that information into a more readable format when sent in an email. Once again JSONata has a set of functions that can be used when working with array structures. This time I use the $map function to convert every array entry into a more readable string of attendee name and email.

Viewing the evaluated sample data, I can see the suggested output of my mapping for the Body field is one that is readable by the receiver of the email.

To now perform the bulk task of emailing fellow attendees, I used a For each node that will iterate over the same array structure that is set on my Set Variable node mapping.

That allows me to construct a standard email template to be sent to all the attendees in that list, again using the Set Variable node mappings:

I then reuse the Set Variable node mappings as the values to insert for the new row in my spreadsheet:

My flow is now complete and ready to switch on.

The Set Variable node provides a much improved authoring experience in defining mappings that you want to reuse in your IBM App Connect flows.

If you had any questions or feedback about this blog please leave a comment below.
You can find out more about IBM App Connect and JSONata using the following links:

Join The Discussion

Your email address will not be published. Required fields are marked *