Tip #1258: Dynamic attribute names in Flow

You know who are the most relentless follow-uppers? Super Simple Flow users, that’s who.

Thank you everyone for your answers to my previous question. I have a follow up question. Is it possible to get the value of an attribute off of an entity dynamically instead of declaratively? E.g. instead of blah?[0]?.fullname something like blah?[0]?[someattributenameIgotinapreviousstep]

Michael “Super Simple Flow User” Ochs

Demo

Let’s consider a scenario where you need to build a full name of a contact while taking into account that some countries do not follow ‘firstname lastname’ convention. For example, to a Westerner, Chinese names are rather complicated. In a real-life implementation I would consider keeping fullname as a separate custom field, just to be on a safe side. But for the demo sake, let’s say we would like to follow ‘lastname firstname’ convention if contact’s account is located in China.

Side note: this Flow also demonstrates a scenario when variables do make sense.

The full flow may look like this:

Let’s break it down.

  • First step is given to us by On Record Selected trigger (on account entity)
  • Second step is getting the last created contact. See Tip #1256.
  • Next two steps simply declare the variables to hold the field names for the first and last names (as they come from CDS)
  • Shall we swap? is a cute name when we check the parent account’s country and swap the attribute names
  • Finally, we’re ready to build the full name. Expression we built in Tip #1257 just got a bit more complicated (I broke it down to separate lines for the readability):
concat(
  body('Get_Last_Contact')?['value']?[0]
    ?[variables('FirstName')],
  ' ',
  body('Get_Last_Contact')?['value']?[0]
    ?[variables('LastName')]
)
  • The last step is unchanged from Tip #1257 – we send ourself a mobile notification with the fullname we just built

The end result (after relocating Alpine Ski House to China):

A mobile notifcation displaying last name then first name for a contact

Time for Doubinski George to take a small break from Flow.

Cover photo by unsplash-logoAndersen Jensen

Leave a Reply

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