Power Automate: Working With Object Variables

  • Introduction
  • Business Use case
  • Implementation
  • Test the flow
  • Summary

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 which do not natively contain the success status. We get the result back as :

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 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 which will accept 3 text inputs that is required for the site creation. We will accept the Site Title, Site Name and Description from the user while triggering the flow.

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

Lets 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 which has the web template ID : SITEPAGEPUBLISHING#0

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

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']

 

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')]

Thus the overall flow will look like :

Test the flow

Lets test the flow by triggering it with manual inputs

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

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

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.