Power Automate: Working With Object Variables

Introduction

Power Automate provides Variables of different datatypes like Boolean, Integer, Float, String, Object, and Array so as to provide a storage mechanism with the running flow. In this article, we will see how we can use the variable of type object to work with a business use case in Power Automate

Business Use case

When we use the Send an HTTP Request to SharePoint action to create a new site, it creates the site and shares back a result body that does not natively contain the success status. We get the result back as :

Graphical user interface, text

Description automatically generated

As per the official documentation of the Site Creation API, the Site Status can potentially 4 values depending on the Success or Failure of the action :

  • 0 – Not Found. The site doesn’t exist.
  • 1 – Provisioning. The site is currently being provisioned.
  • 2 – Ready. The site has been created.
  • 3 – Error. An error occurred while provisioning the site.

In such a situation, Having this table maintained as a Variable Object will help us cross-check the returned Site Status against the variable to pick the status and intimate an end-user.

Implementation

To test this scenario, we will create a manually triggered flow that will accept 3 text inputs that are required for the site creation. We will accept the Site Title, Site Name, and Description from the user while triggering the flow.

Graphical user interface, text, application, email

Description automatically generated

We will then declare a Site Status Variable which will contain the Site Status ID and the corresponding Outcome Message as an Object variable.

Graphical user interface, text, application, email

Description automatically generated

Let’s add the action Send an HTTP request to SharePoint to provision the site. We will issue a POST request to the URI – _api/SPSiteManager/create and keep the Site Address as the SharePoint Admin Center URL. In the Body, we will paste the request payload with the below values:

Title

The Title that should come up in the Site Title bar

URL

The URL where the site should be provisioned, we are getting the Site Address from the user that should come after /sites

Lcid

Locale identifier. By default 1033 is English(United States)

Description

Description for the site obtained from the user

Web template

By default, we are creating a communication site that has the web template ID: SITEPAGEPUBLISHING#0

Graphical user interface, text, application, email

Description automatically generated

The action will start the site provisioning process and return back the output in the format :

Graphical user interface, text, application, email

Description automatically generated

So as to get the SiteStatus Value from the returned JSON object, we will initialize a strong variable- varOutputStatus and extract the value using the expression :

outputs(‘Send_an_HTTP_request_to_SharePoint’)?[‘body’][‘d’][‘Create’][‘SiteStatus’]
Graphical user interface, text, application

Description automatically generated

This will fetch the SiteStatus. Say for instance if provisioning is completed, the status returned would be 2. Now we will have to fetch the corresponding Status text from the Variable object we have initialized. To fetch this, We will use the below expression where we will index into the varStatusCollection with the SiteStatus that we received from the HTTP Action and get back the Site status Text which we will use in the mail body to intimate the user.

variables(‘varStatusCollection’)[variables(‘varOutputStatus’)]
Graphical user interface, text, application, email

Description automatically generated

Thus the overall flow will look like this:

Graphical user interface, application

Description automatically generated

Test the flow

Let’s test the flow by triggering it with manual inputs

Text

Description automatically generated

The Site Creation is completed by the HTTP Action and has returned the Site Status as 2

Graphical user interface, text, application, email

Description automatically generated

We have also received the mail with the Site Status Text that was retrieved from the Variable Object

Graphical user interface, text, application, email

Description automatically generated

Summary

Thus, we saw how to use the Array Object in Power Automate using a real-time use case how you can fetch the Site Status code and compare it with the Status Text stored in the Array object to determine the site creation Success/Failure.

Related Articles

Author

Author

Priyaranjan KS is a Modern Workplace Architect primarily focused on developing and architecting solutions around Office 365,Power Platform and Azure.He is also a Microsoft Most Valuable Professional(MVP) and a Microsoft Certified Trainer(MCT)

Latest Articles