Using triggerBody() / triggerOutput() to read CDS trigger metadata attributes in a Flow | Power Automate

Now, for all the newbies working with Common Data Service (Current Environment) connector face a little constraint in order to read certain fields which are NOT in the list of the Dynamic Content of the CDS connector itself.

Scenario

Let’s say you want to read this field from the Body / Outputs of the CDS trigger in a Flow in Power Automate

Attributes (or rather supporting metadata) won’t be accessible directly since it’s not from the context of the CDS connector itself like you see for other fields as below –

Flow

In this example, here’s how our Flow will look like.

We’ll declare 2 variables after the CDS connector with Create or Update trigger on Accounts entity and how we can work with the results.

Reading from triggerBody()

When to use triggerBody() ? – When you want to fetch attributes from the body of the trigger.

Here’s how you can use triggerBody() function to read ‘RunAsSystemUserId’ from the outputs of CDS connector.

  1. Let’s say you have a variable declared to store your results. Let’s call it Trigger Body. Click on the fx sign to enter the formula

  2. Now, in the formula, enter triggerBody()?[‘RunAsSystemUserId’]. triggerBody() is a method to you’ll find it in auto-complete

  3. And the variable will look like this

Result of triggerBody() will be as below

Reading from triggerOutputs()

When to use triggerOutputs() ? – Whenever you need to access anything from within the body as well as some info from the header as well as shown in the 2nd screenshot in step #2 below.

Here’s how you can use triggerOutputs() funtion to read ‘RunAsSystemUserId’ from the outputs of CDS connector

  1. Let’s say you have a variable declared to store your results. Let’s call it Trigger Output. Click on the fx sign to enter the formula


  2. Now, in the formula, enter triggerOutputs()?[‘body/RunAsSystemUserId’]. triggerOutputs() is a method to you’ll find it in auto-complete.


    The reason this we write “body/RunAsSystemUserId” is because in the JSON structure of the complete Outputs of the CDS Connector, you’ll see that RunAsSystemUserId attribute lies inside body in the JSON.
    Whereas in terms of triggerBody() above, we are reading attributes from the “body” itself.

Result of triggerOutputs() will be as below

Hope this was useful!

Here are some more Power Automate / Flow posts you might want to check –

  1. Call HTTP Request from a Canvas Power App using Flow and get back Response | Power Automate
  2. Send a Power App Push Notification using Flow to open a record in Canvas App | Power Automate
  3. Accept HTTP Requests in a Flow and send Response back | Power Automate
  4. Terminate a Flow with Failed/Cancelled status | Power Automate
  5. Adaptive Cards for Teams to collect data from users using Power Automate | SharePoint Lists
  6. ChildFlowUnsupportedForInvokerConnections error while using Child Flows [SOLVED] | Power Automate
  7. BPF Flow Step as a Trigger in CDS (Current Environment) connector | Power Automate
  8. Pause a Flow using Delay and Delay Until | Power Automate
  9. Generate Dynamics 365 record link in a Flow using CDS connector | Power Automate
  10. Text Functions in a Flow | Power Automate
  11. Loop through array of objects in a Flow & Create records in CDS | Power Automate
  12. Get Count of records retrieved in CDS connector in a Flow | Power Automate

Thank you!

Advertisement

4 thoughts on “Using triggerBody() / triggerOutput() to read CDS trigger metadata attributes in a Flow | Power Automate

  1. How did you build those ‘TriggerBody’ and ‘TriggerOutput’ controls I don’t see it as an Option in the Flow builder?

    Like

    • Hi Simon, can you check if you have turned on Experimental Features for Flow. Alternatively, please do Ctrl + Shift + Space or Ctrl + Space to force the Menu.
      Refresh the browser once as well. I’ve faced this before, but not sure on what occasion. Hope this helps!

      Like

  2. Great job, thanks. I just had to make some modifications tu your expression:

    add(div(add(dayofyear(addDays(subtractFromTime(utcNow(), if(equals(dayofweek(utcNow()),0),6,sub(dayofweek(utcNow()),1)), ‘Day’),3)),6),7),1)

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.