cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How can I update an environment variable from a flow

Hi, great to see it's now easy to read an environment variable in a flow (provided the flow is created within a solution!) but how to update the value of the environment variable from within the flow?

 

I assume I will need to use the Dataverse connector's Update a Row function so I start by retrieving the environment variables UID using 'List rows' : -

1.png

This appears to work and I can reference the UID using: -

 

first(outputs('Get_SMSyncInitialise_UID')?['body/value']?[0]?['environmentvariabledefinitionid'])

 

BUT when I try and reference that UID to update the environment variable record ...

 

2.png

 ... I receive the error: - "Bad Request - Error in query syntax."

 
Stumped 😞 Any pointers please?

 

Cheers

2 ACCEPTED SOLUTIONS

Accepted Solutions
EricRegnier
Super User
Super User

Hi @Anonymous,

You're setting the row ID of the update step to "Environment Variable Definition" ID, but should be the row ID of "Environment Variable Value". In the "GetSMSSyncInialise" list row step, use the "Expand Query" to include related environment variable values. This will give you the "Environment Variable Value" ID to update. Then iterate from the rows returned and update the value within the loop.

Hope this help! 

View solution in original post

Anonymous
Not applicable

Thank you @EricRegnier for pointing me in the right direction

 

In the end, instead of using an Expand query for List Rows I used the excellent FetchXML Builder tool (from XRMToolbox) to generate an XML Query that pulled out just the UID as follows: -

 

<fetch>
  <entity name="environmentvariabledefinition" >
      <filter>
        <condition attribute="schemaname" operator="eq" value="hdc_SMSyncInitialise" />
      </filter>
    <link-entity name="environmentvariablevalue" from="environmentvariabledefinitionid" to="environmentvariabledefinitionid" >
      <attribute name="environmentvariablevalueid" alias="envUID" />
    </link-entity>
  </entity>
</fetch>

 

... and the expression: -

first(body('Get_Environment_Variable_UID')['value'])['envUID']
 
... in the Update a Row 'Row ID' field.

 

All working 🙂

View solution in original post

2 REPLIES 2
EricRegnier
Super User
Super User

Hi @Anonymous,

You're setting the row ID of the update step to "Environment Variable Definition" ID, but should be the row ID of "Environment Variable Value". In the "GetSMSSyncInialise" list row step, use the "Expand Query" to include related environment variable values. This will give you the "Environment Variable Value" ID to update. Then iterate from the rows returned and update the value within the loop.

Hope this help! 

Anonymous
Not applicable

Thank you @EricRegnier for pointing me in the right direction

 

In the end, instead of using an Expand query for List Rows I used the excellent FetchXML Builder tool (from XRMToolbox) to generate an XML Query that pulled out just the UID as follows: -

 

<fetch>
  <entity name="environmentvariabledefinition" >
      <filter>
        <condition attribute="schemaname" operator="eq" value="hdc_SMSyncInitialise" />
      </filter>
    <link-entity name="environmentvariablevalue" from="environmentvariabledefinitionid" to="environmentvariabledefinitionid" >
      <attribute name="environmentvariablevalueid" alias="envUID" />
    </link-entity>
  </entity>
</fetch>

 

... and the expression: -

first(body('Get_Environment_Variable_UID')['value'])['envUID']
 
... in the Update a Row 'Row ID' field.

 

All working 🙂

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Users online (2,444)