Blog

Get the difference between two dates EASY

We have all been there, we need to check the difference between 2 dates, and if you ever had to implement this you would need to use some crazy mathematical equations using the ticks() expression. But now..

I’m not sure when this expression got added, but we can now use dateDifference() expression instead of using ticks().

The dateDifference() expression is a powerful tool in Power Automate and Logic Apps for calculating the difference between two dates.

Allowing to easily determine the number of days, months, or years between two dates, which can be useful in a variety of scenarios.

  1. Syntax and Parameters
  2. How to Use
  3. Extracting the Result
    1. Extracting Days
    2. Extracting Hours
    3. Extracting Minutes
    4. Extracting Seconds
  4. Things to Know
  5. Links

Syntax and Parameters

The syntax is easy with only 2 parameters:

dateDifference('<startDate>', '<endDate>')

How to Use

Below is a simple example of how to use this expression:

dateDifference('2015-02-08T10:30:00', '2018-07-30T14:45:30')

This returns

"1268.04:15:30"

The result is in the format of:
Days.Hours:Minutes:Seconds

Note:: If the dates passed in have no time interval, the result shows zeros for the hours, minutes, and seconds. We can extract the different parts of the return by using some expressions inside a Compose action, which we will do next.

Extracting the Result

If you need to extract certain parts of the result into the hours, minutes, or even seconds, you can use the split() expression.
Below you will find the explanation on the extraction, as well as the exact expressions to use.

  • The split() function splits the output of dateDifference() at the period (‘.’) into an array with two elements: days and the rest (hours:minutes:seconds).
  • The [0] indexer retrieves the first element of the array, which represents the number of days.
  • The int() function converts the days from a string to an integer.
  • Replace the date time values with your dates/time

Extracting Days

To extract the days from the result we can use

int(split(dateDifference('2015-02-08T10:30:00', '2018-07-30T14:45:30'), '.')[0])

This returns:

1268

Extracting Hours

To extract the hours interval from the result we can use

int(split(split(dateDifference('2015-02-08T10:30:00', '2018-07-30T14:45:30'), '.')[1], ':')[0])

This returns:

4

Extracting Minutes

To extract the minutes interval from the result we can use

int(split(split(dateDifference('2015-02-08T10:30:00', '2018-07-30T14:45:30'), '.')[1], ':')[1])

This returns:

15

Extracting Seconds

To extract the seconds interval from the result we can use

int(split(split(dateDifference('2015-02-08T10:30:00', '2018-07-30T14:45:30'), '.')[1], ':')[2])

This returns:

30

Things to Know

There are a few things to be aware of:

  • Be aware of time zones, Power Automate uses UTC as a baseline for all time formats.
  • If pulling dates from SharePoint be aware of what time zone your site is in.
  • You can convert the time zones by using expressions or by using actions. Read more about converting time zones here.

date Difference – Reference guide for expression functions – Azure Logic Apps | Microsoft Learn

Dataverse Record Level Security

Record (row) level security in Canvas or Model-driven apps. Using Dataverse security models.

The scenario here is to enable row level security within the concepts of Dataverse inside a Model-Driven App. Important to note, this can be applied to Canvas or Model-driven apps.

For example:
I have a Sale Commission table which is connected to a Model-Driven App. One of the columns is a choice called Store.

The concept is; we only want users to see records from their own respective stores. This concept seems straight forward and easy.. After some digging and reading documentation and asking some friends in understanding this model. I found a way to do this. So here it is!

Video Tutorial

Prerequisites

The feature that will help us in this concept is called Matrix data access structure (Modernized Business Units). Click the link to read more into it. But I will articulate what we need to do.

Enable record ownership across business units (preview)

First we need to enable this feature on an environment. Follow the steps below to enable this feature.

  1. Sign in to the Power Platform admin center, as an admin (Dynamics 365 admin, Global admin, or Microsoft Power Platform admin).
  2. Select the Environments tab, and then choose the environment that you want to enable this feature for.
  3. Select Settings > Product > Features.
  4. Turn On the Record ownership across business units toggle.
  5. Click Save.
Record ownership across business units (Preview)

Setup steps

This guide is assuming you have your Dataverse tables built.
We need to setup a few things to get this functionality to work:

  1. Create Business Units
  2. Create security role
  3. Assign security role
  4. Create Business rule

Create Business Units

We are creating a Business unit for each “Store” in this example.
Creating business units in the Power Platform Admin center:

  1. In the Admin center, select your environment.
  2. Select the Settings cog in the top.
  3. Under Users + permissions.
  4. Select Business units.
Showing step 4. Clicking Business units
  1. Click New, and create as many business units as you need.
  2. In this example, I am creating 3. One for each store.
Showing all business units that have been created

Create security role

We want to create a security role. This is a role to give access to the custom tables we have for Dataverse, as well as privileges for Business unit. This will allow users to append different Business units to new records.

While still in the Admin center;

  1. Click See all under Security roles.
Admin center showing the security role option
  1. Click, New role or edit an existing role.
  2. When editing the role click the Custom Entities tab.
  3. Find your table that users will be interacting with. In this example, its Sale Commission table.
  4. Set this table to:
    Read = Business unit
    Create = Parent child business unit
Showing the Sale commission permission
  1. Next, click the Business Management tab.
  2. Set the Business Unit table to:
    Read = Parent child business unit
    Write = Parent child business unit
    Append To = Parent child business unit
Showing the Business Unit permissions
  1. Click Save and Close.

Assign security role

Now we need to assign the security role to users based on the Business unit. To do that follow the steps:

While in the Admin center;

  1. Click See all under Users.
  2. Select a user to assign the Business unit role to.
  3. Click Manage roles.

Notice that we can change the Business unit the Security role can be assigned under.

Showing the new option to select Security roles under each Business unit

In this example, I am assigning the role under each Business unit to give permissions.

  1. Select the Business unit and assign the role.
UserRoles assigned + Business unit
AdeleSales Contributor in MainStore-BU
AlexSales Contributor in NorthStore-BU
Sales Contributor in DowntownStore-BU
Showing a table of permissions

Based on the table above.

  • Adele can see all records part of the Main store
  • Alex can see all records in North Store and Downtown Stores
  1. Click Save.

Create Business rule

Now that the feature has been enabled and configured, we still need to change the Owning Business Unit field based on the selected store. There are many ways to do this, but for this example, I will be using a Business rule.

To configure a Business rule;

  1. Navigate to your solution, or where the table (Sale Commission) is in Power Apps.
  2. Select the table, and click Forms.
  3. Select the form that users will be using when creating records.
  4. Once the form is opened, add the Owning Business Unit field, and select it
  5. Once selected, click Business rules on the right pane.
  6. Click New business rule.
  7. Give the rule a meaningful name.
  8. In the default condition, in the properties tab mine looks like this:
Business rule condition 1

For the rule, I am going to add a Condition to the “is false” and continue to do this for each Business unit / Store I want to check.
Here is what mine looks like after adding all the conditions:

All conditions added to Rule

Next we need to Set the values of the business unit based on the store.

  1. In the components tab, add a Set Field Value action to all the “Is true” paths.
  2. With the Set Field Value selected, click on the Properties tab.
  3. Select Owning Business Unit for Field and the right Value. Example for the NorthStore:
Set Field Value properties for North Store
  1. Do this for all the Conditions. Mine looks like this:
Completed Business Rule
  1. After you’re done, click Validate.
  2. If validation is good, click Save.
  3. After saved, click Activate.

That’s it. Done!!
Now when a user selects the Store, it will automatically change the Owning Business Unit.

Form view of Owning Business Unit changing based on Store selected.

Tip For Testing Your Flows In Power Automate

Wouldn’t it be nice if we can Test our Flows without executing some of the actions like Sending Emails, creating items in SharePoint or Dataverse?

Guess what we can! And its very easy to do. Check this out!

If your like me, you test your Flows over and over again. This results in sending unwanted emails, creating items in SharePoint or Dataverse, Creating files on OneDrive or SharePoint.
Every time you test your Flow, these actions inside our Flow get executed and cause unwanted behavior when Testing.

Wouldn’t it be nice if we can Test our Flows without executing these actions? Guess what we can! And its very easy to do. Check this out!

Scenario

For example, I have a Flow that Create a new row in Dataverse, and then send an email to the person who created the new row. That is fine, but what happens when we have other actions in our Flow that we want to test to make sure they are correct.
I may want to test the Flow multiple times if I am doing some data manipulation, but this will result in Creating multiple unwanted rows (records) in Dataverse, as well as send emails every time.

We can clean up the testing process easily.

How?

We can utilize a feature called Static Result.

First click the 3 dots on the action, and select Static Results.

Next we can configure the static results. For easy example click the radio button to enable, select your Status, and the Status Code.

Click Done.

Now the action will have a yellow beaker, indicating that the action is using Static results.

Things to note:
– Static Result are in ‘Preview’ so it could change at any time
– Not all actions will be able to use them
– If the option is greyed out, and you’re certain the action is able to use it, save the Flow and re open

This is only the beginning, as you can create a custom failed response, or create any result you want. This can help troubleshooting and testing certain scenarios.

REMEMBER!! To turn off static results when you want to execute the actions like normal.

Examples

Some examples on when to use static results:

  • Flow runs without sending emails
  • Flow runs without Approvals needed
  • Flow runs that need to test errors on certain actions
  • Flow runs testing different error codes (Advanced) + Custom error codes

Conclusion

I have used this feature for awhile now, and noticed not many know about it. It’s so useful in many testing scenarios. Just remember to disable the static results once your done testing!

If you have any questions or want to add anything please leave a comment and like this post! Thank you!

How to Use Regular Expressions in Microsoft Power Virtual Agents With Examples

Have you used RegEx in your PVA bots? Check out this post where I give patterns to the most common validations.

Regular Expressions in Power Virtual Agents? Sounds like a pretty advanced topic. But it’s actually not that difficult and can save you hours of time if you’re trying to validate user input for things such as credit card numbers, tracking IDs, custom invoice numbers or even IP addresses. In this post we’ll cover some of the basics of Regular Expression syntax so you can get started using them inside Power Virtual Agents.

Summary

To utilize regular expressions inside Power Virtual Agents, we must first create a new entity.
This can be be done by clicking the Entities tab > New entity.

Now select Regular expression (Regex)

PVA does a great job in providing some general use case examples.

The syntax is based on .NET


RegEx Examples in PVA

Below you will find some examples you can copy and paste directly into the Pattern for your Regular Expression:

PatternDescription
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$IP Address
– Looks for X.X.X.X format
– Each X range in 0-255
– X length 0-3
^4[0-9]{12}(?:[0-9]{3})?$Visa Credit Card numbers
– Start with a 4
– Old cards use 13 digits
– New cards use 16 digits
^3[47][0-9]{13}$American Express
– Starts with 34 OR 37
– All have 15 digits
 ^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$Mastercard
Starts with either:
51-55 OR 2221-2720
– All have 16 digits
^(?!0{3})(?!6{3})[0-8]\d{2}-(?!0{2})\d{2}-(?!0{4})\d{4}$Social Security Number
– SSN are 9 digits
– Looks for XXX-XX-XXXX format
– Cannot contain all zeros
– Cannot begin with 666 OR 900-999
^[a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5}$Mac Address
– 6 byte hex separated by colon “:” OR dash “-”
^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))$Port Number
– Matches valid port number in computer network
– 16 bit
– Ranges from 0-65535
[A-Z]{2,}-\d+Jira Ticket Number
– Looks for format Hyphen-separated Jira project key and ticket issue number
^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$Bitcoin Address
26-35 alphanumeric characters
– Start with 1 OR 3 OR bc1
^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$UUID / {guid}
– 36 characters
– 128 bit, represented in 16 octets
– Looks for format form of  8-4-4-4-12

Using them in PVA

Once we create the Entity, and define the pattern for our RegEx. We can now use this validation inside our PVA chat.

For example, I will test the IP Address pattern

^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

I have created a topic for testing my RegEx.

To use the newly created entity, Add a Question, under Identify select your Custom Entity

Under this, I add a message to confirm its valid.
(Note, the bot will automatically let the user know if the validation does not match)

Testing the RegEx

Okay, drumroll….
The values I will be testing are

User InputValid?
192.168.1.1Valid ✔
127.0.0.1Valid ✔
999.55.1.5Not Valid ✖
Not A IP AddressNot Valid ✖

Conclusion

Being able to use Regular Expressions inside Power Virtual Agents can be extremely powerful. And with the above list of common patterns, I hope you find value in this post.

Thank you, and have a great day!

Power Apps Choosing Which Connections To Use Using Power Automate

Uploading data from Power Apps can be scary on a security standpoint, since the user will need access to the Data Source. Lets use Child Flows to get around this, and use any connection we want.

You may have run into an issue when creating Power Apps that needs to submit data to SharePoint, Dataverse, etc. But did not want to give everyone in the app access to these.
The problem is, Power Apps uses the connections of the user using the app, meaning if the app writes to a SharePoint List, the user will need Read/Write access.
The same goes for Power Automate if we try to send the data to Power Automate from Power Apps, it still uses the users connection who triggered the Flow.
How can we get around this? Read below!

Table of Contents


Known Issues

  1. If you block the HTTP Request connector via data loss prevention (DLP), child flows are also blocked because child flows are implemented using the HTTP connector. Work is underway to separate DLP enforcement for child flows so that they are treated like other cloud flows.
  2. You must create the parent flow and all child flows directly in the same solution. If you import a flow into a solution, you will get unexpected results.
    Call Child Flows – Power Automate | Microsoft Docs

Prerequisites

  1. The Flows must be created inside the same Solution, so a Dataverse database must be configured on the Power Platform Environment

The Scenario

In this scenario, I will be showing how a user can use Power Apps to create items in a SharePoint List without being a member of the Site. This will allow us to use a specific Service Account to create the data in SharePoint without giving the user in the app any permission at all!

First we will build the Child Flow, then Parent Flow, and lastly customize the Power App

Child Flow

Inside your Solution create a new Cloud Flow.

  1. For our trigger we use a Manual Button, and add the data we are expecting from Power Apps to put inside our SharePoint List
    (In my example I am only bringing in one field for Title)
  2. Next, I add a Create Item action for my SharePoint List, and add the Parameters from the trigger inside the action.
  3. Lastly, I add a ‘Respond to PowerApp or flow’ action, I create an Output called Success, and some details about what was created.
Child Flow


Make sure to use the Connection you want users of the App to use for the SharePoint Create item action.

Save and go back to the Flow dashboard screen (where you see the Details and run history screen).

There will be a Card on the right side called ‘Run only users’ click Edit

Run only users

Under Connections Used, switch ‘Provided by run-only user’ to the connection you want to be used by users of the App
(They wont have access to this Connection outside this Flow)

Run only user

Click Save,

Now onto the Parent Flow

Parent Flow

Go back to the Solution and Create another Cloud Flow.

  1. For our trigger we use the PowerApps button trigger.
  2. As best practice, create Variables for your data that is coming from Power Apps. Don’t forget to name them, as this will be the parameter name in Power Apps,
    Use the ‘Ask in PowerApps‘ dynamic content for your variable values.
  3. Next we use a action called ‘Run a Child Flow’
    (If you do not see this action, your Flow was not created inside a Solution)
    Add the parameters (these were the input parameters from the last Flow that we just created).
  4. Lastly, add ‘Respond to a PowerApp or flow’ action. For this demo I am adding the parameter ‘Success’ this is from the child Flow.


Click Save.

Power App

Now onto the Power App, I am going to create a simple Power App with 1 TextInput for Title, and a Button to Pass the data to Power Automate.
Here are my controls for reference:

TextInput_Title
Button_SendToFlow

For the Button:
1. Add the Flow to the button by clicking on the Button,
2. Clicking Action tab on top of page,
3. Clicking Power Automate
4. Select the Flow


Next add the parameters for the Flow, in my case I am adding the TextInput_Title.Text

Now, I want to add a Notification that the Item has been added, which will confirm my Flow has Run correctly. Ill be using the ‘Success’ Output parameter from the Flow for this.

To add this, I put my Flow run inside a Variable inside Power Apps. Ill call my variable Results, and IO add this to the OnSelect property of the Button where my Flow is:

Now I use the ‘Notify’ function to notify the user of the item being created, I add this after the semicolon. So my function looks like this in the end:


So my final code looks like this:

Set(
    Results,
    'PA-Trigger1'.Run(TextInput_Title.Text)
);
Notify(
    Results.success,
    NotificationType.Success
);
Reset(TextInput_Title)

Now lets test it!

Conclusion

I am using a User called ‘Demo User’ I have shared the App with this user. But they are not part of the SharePoint Site


Here is the SharePoint Site:

Now Logged in as the Demo User to test this:

Logged in as Demo User


Button Clicked >

Button Pressed, Flow Completed

Now to check SharePoint >

Test Success!!

Done!
So this was just a basic example on how we can create data inside a Data Source that the user of the App does not need access too.

Check Conditions In Power Automate During Run

Is your IF condition always evaluating to False? Debugging and Testing your Flows should be easy. When using a Condition in Power Automate, in the run we cannot see the expression or the results of what is being evaluated.

I will go over a quick workaround to debug and find out what is happening in the condition

The Problem?

Is your Condition not working as expected?
The problem is when we use a Condition action inside Power Automate, we cannot see the “equation” that is being evaluated when looking into the run.

The problem affects how we can troubleshoot, the following solution will show what is happening inside the Condition action during the run.

Scenario

In this scenario, I am checking:
If one value is greater than a second value

Now during a test run, I expect to see this condition true, but in my run it is always showing false and going in the If no branch.

The big problem is though, I cannot see what the values being evaluated look like. Take a look below

Clicking on the “Show raw inputs” is also not helpful..

Solution

So what is this quick and easy solution to see the condition results? A simple ‘Compose‘ action.

Lets take a look:
First add a Compose under your Condition

Next copy the values that are in the Condition to the Compose.
My Compose now looks like this:

Now make sure the Compose is above your Condition.
I am just dragging the Condition below the Compose

Next, we can run the Flow again, and see what the Compose can tell us:

Yikes! We can see our 2 values that are being evaluated are both 15.
And 15 is not greater than 15. This is why its returning false.

My Thoughts

In my opinion, this should be already visible inside the Condition action. To get this feature added to Power Automate, we can vote on this feature. Head over to the Community Forum and vote for this idea.

View details of Condition results in runs – Power Platform Community (microsoft.com)

The more votes, the better the chances of the Product team implementing this.
Thank you for reading, and have a great day!

Where Are My Flows When Building Power Virtual Agents In Teams

You added a Flow in Power Virtual Agents in Teams, you now want to edit that Flow. Where is it? Come check out the answer!

Overview

Building Power Virtual Agents (PVA) in Microsoft Teams is fast, easy, fun, and powerful, especially when we add Power Automate to the mix. A couple questions come up:

1. After the bot is build, how do we edit the Flows? Do we have to go into the PVA bot inside of Microsoft Teams?

2. Where are the Flows stored?

The Answer

The answer to the above questions, can be simplified into one response.

All Flows built inside the Teams environment for PVA chatbots are stored in the Teams environment under the Default Solution.
Now.. How do we get there?

Navigate to the Power Automate Web Portal
Power Automate | Microsoft Power Platform

Sign in, and select the environments menu in the top right and choose the Environment that correlates to your Teams name where you built the Bot.
My Microsoft Team name is ‘POC – Teams

Next navigate to the Solutions tab on the left, and select ‘Default Solution


Once inside the ‘Default Solution‘ we can see many different types of artifacts. To narrow this list down:
On the top right of the page there is a dropdown with different types. Select ‘Flow

That’s it. Now we can see all the Flows inside this Teams Environment.

Want to learn how to get user info from Office365 to use in Power Virtual Agents? Check out my blog on the flow you see above
Get User Info

Limitations

There are some limitations:
– There is no way to import a Flow into this Environment

– When using the Save As feature, the Flow is saved outside of the Solution, thus cannot be used for your PVA Bot in Teams

– When modifying the Flows Inputs and Outputs you will have to remove the Flow action inside of PVA to properly refresh.

Conclusion

If you need help with anything Power Platform related, check out the community sites:

Power Virtual Agents Community – Power Platform Community (microsoft.com)

Power Automate community (microsoft.com)

Power Apps community (microsoft.com)

Home – Microsoft Power BI Community

Getting User Details To Use In Power Virtual Agents (Teams)

Lets use Power Automate inside Power Virtual Agents to get all the users details who is interacting with the bot. We can customize our greetings, or simply use any information that Office365 returns

Things to Know

This examples is based on building a Virtual Agent in Microsoft Teams.
We will be using the ‘Only for teams’ Authentication on the bot.

Summary

By default PVA in Teams has some valuable variables handy, like ‘bot.UserDisplayName‘. This is awesome, but what if we want more information about the logged in user?

This post will show both scenarios, on using the bot.UserDisplayName variable as well as getting all the user details that are stored in Office365 like:
– Email Address
– First Name
– Last Name
– Job Title
– Etc.

We can also use this in the Greetings Topic to address the user by their first name, rather than their display name. (Keep in mind this might affect performance by a couple seconds)

Contents

Bot Setup
Scenario 1 (Display Name)
Scenario 2 (Office365 Details)
Conclusion

Bot Setup

Once you have your Bot created, make sure the Authentication is set to ‘Only for teams’. To check click
Manage > Security, Authentication

For this example we will be using the ‘Only for Teams’ option. This will work for ‘Manual’ as well, but will require additional steps to setup a App Registration in Azure.

Select ‘Only for Teams’

Customize Greeting Scenario 1 (DisplayName)

After enabling the Authentication, you will now have access to Two variables,
bot.UserDisplayName
bot.UserId

Now lets customize our greeting.

Navigate to ‘Topics’ and select the ‘Greeting’ Topic, this is under ‘System Topics’. Click on the Authoring Canvas button.

Inside the message under the Trigger, you can customize the greeting message to include the variable bot.UserDisplayName

Testing this, the Bot now knows my Display Name. This variable can be used in any topic. Which gives the Bot more of a human type feel.

To get all the user details from Office365, scenario 2 will cover this

Customize Greeting Scenario 2 (Office365)

Navigate to ‘Topics’ and select the ‘Greeting’ Topic, this is under ‘System Topics’. Click on the Authoring Canvas button.


Under the ‘Trigger Phrases’ and select ‘Call an action’. We will now build a new Flow to get the user details we want.

You will now be navigated to a new screen where you will build your Flow.
Select the Basic PVA Flow Template

First give the Flow a meaningful name. Mine is:
Power Virtual Agents – Get User Info

Add a Text Input to pass in the Display Name variable

Next add a ‘Search for users‘ action from office365 connector, and pass in the PVA dynamic value from the trigger

Now we have all the user details. The results are returned as an Array. To get around this.
We can add a ‘Get user profile‘ action and pass in the first User Principal Name(UPN)

We have to use the first() expression, so we don’t get put into an Apply to each loop, my expression:

first(outputs('Search_for_users_(V2)')?['body/value'])?['UserPrincipalName']
@{first(outputs(‘Search_for_users_(V2)’)?[‘body/value’])?[‘UserPrincipalName’]}

Lastly in the Return values to PVA action, add all the values you want from ‘Get user profile‘ dynamic content

Click Save, and close on top right of the screen. Back at the PVA Canvas screen, add your Flow

Pass in the bot.UserDisplayName variable

Now we can customize our greeting to only address the user by first name

As a test I created a Topic called User Details

Conclusion

This can be a great way to give your bot more personality. Do keep in mind that this may affect performance.

Checking If HTML Table Is Empty In Power Automate

I needed to check if an HTML table had data or not. Usually when I need to check I have two expressions I like to use: ’empty()’ or ‘length()’.

The Problem

I needed to check if an HTML table had data or not. Usually when I need to check I have two expressions I go to first.

  1. empty()
  2. length()

I tried using empty() and found that the HTML table even when empty, is not truly empty.
I then tried length() and found that when the HTML table is empty there is still a length of 30.

The Scenario

I have some data that is used to track different devices that can be loaned out. The data has properties like, Type of device, Serial Number, Etc.

The data comes in, and looks like this:

[
  {
    "type": "Phone",
    "device": "iPhone 11 Pro",
    "serialNumber": "0007488"
  },
  {
    "type": "Phone",
    "device": "Samsung Galaxy S20",
    "serialNumber": "1166289"
  },
  {
    "type": "Watch",
    "device": "Apple Watch Series 5",
    "serialNumber": "00013701"
  },
  {
    "type": "Laptop/Tablet",
    "device": "Surface Pro X",
    "serialNumber": "AA78442"
  }
]

I want to put this array of data inside a HTML table and send it out on an email. The problem is, my data might be empty, as only available devices will show up in my data.

I need to check if the HTML table is empty, if it is empty:
If True:
Send email with HTML table
If False:
Send email without HTML table

The Flow

For this Flow, I will be using an Array Variable to simulate my data coming in from another system.
I will call this Variable ‘Data‘.
The HTML table action will be added underneath.
You will need to determine if you want to use ‘Custom columns‘ or ‘Automatic columns‘ This can be done in the advanced options in the HTML action:

My ‘Data‘ Variable is empty at the moment. This is what we want for our first run, we want to get the length of the HTML table when its empty.

Next add a ‘Compose‘ action, and use the expression length(), pass in the HTML table as the parameter. For example, my expression looks like:

length(body('Create_HTML_table'))

Now run the Flow with no Data in the HTML table, and check your Compose action to see what the length is. In my case it is 30

Now we can add a If Condition to check if the length is greater than 30

** TIP **
I am passing in the Compose action into the condition, this allows me to see what the outputs of the Compose action before it gets evaluated inside the condition. This is extremely useful for troubleshooting

Conclusion

The Flow will go into the ‘If yes’ block if the HTML table has data

The Flow will go into the ‘If no’ block if the HTML table is empty

Of course checking the Data Variable itself for length could work way better. This example is mainly for data that can come in that could have loads of junk. For example:
An HTTP API could bring in no data, but still have other information attached like, headers, status code, version. In this case we can only do conditional checks on the HTML table, since our Data variable will always have something being passed in.

I used this method to help someone on the Community Forum, check it out here:
https://powerusers.microsoft.com/t5/Building-Flows/Create-a-Flow-with-Condition-that-does-not-send-email-when-list/m-p/721076/highlight/false#M98488

Getting Specific Files And IDs In SharePoint Using Power Automate

I encountered an issue when trying to filter a a file by filename, that was in a SharePoint document library.

When needing to get a specific SharePoint file ID. It can be troublesome to filter the Files. For example Using a ‘Get files’ action we can see that the properties of the file are encased inside {} meaning that SharePoint is using some calculation on the Document Library to create these fields.

Contents

This post will go over a common problem I have seen using SharePoint action to get a specific file ID.
There are three parts to this post:
The Problem
The Solution
Conclusion

The Problem?

I encountered an issue when trying to filter a a file by filename, that was in a SharePoint document library.

When needing to get a specific SharePoint file ID. It can be troublesome to filter the Files. For example Using a ‘Get files‘ action we can see that the properties of the file are encased inside {} meaning that SharePoint is using some calculation on the Document Library to create these fields.

Attempting to use a filter query on any of the fields encased between {} returns an error. For example I am trying to filter the file called ‘Readthis.txt‘ I get a ‘Bad Request’ Error:

The error message I receive is:

Column ‘Name’ does not exist. It may have been deleted by another user.
clientRequestId: 75462fg8-686d-48p1-5se7-e8l97jk84025
serviceRequestId: 75462fg8-686d-48p1-5se7-e8l97jk84025

I have read online that using Title as the column name is correct, although I do not get an error, the output is empty.

The Solution

Now the best part, the solution!

The way I have been using to filter out ‘Get files‘ action is by using the ‘Filter array‘ action. This action will allow us to filter the calculated columns that SharePoint is using, like {Name}, {Link}, {FilenameWithExtension}, Etc.

To get setup, we want the ‘Get files‘ action to pull in ALL files, so we don’t want to have any filter at this stage.

Now add a ‘Filter array‘ action, put the dynamic content value in the From field. On the left side select the dynamic content from the ‘Get files‘ action. The right side put what you want to filter on.
So for example, I want to filter and get the file ‘Readthis.txt‘. So my ‘Filter array‘ action looks like this:

Now when running the Flow, the ‘Filter array’ action is properly filtering out the filename:

Conclusion

I wrote this blog post based on a scenario I have helped solved on the Power Automate Community Forum.

Hopefully someone else find this information useful.

Thanks for reading!