Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

Why the condition is false for the same numbers (Power Automate)

“I have two numbers, they’re the same, yet the condition in Power Automate evaluates as ‘false’ when comparing them!”


Comparing two numbers is such a common functionality in many Power Automate flows. You have two numbers and depending on their comparison the flow will do something. It can be a backup column to avoid infinite trigger loop via trigger condition, a rating from Forms, or just any two numbers. Yet even if the numbers look the same in the flow, when used in a ‘Condition’ it always returns ‘false’! Why? Why does it tell you that it’s not the same number even though you can see it is?

The same character, different format

If the ‘Condition’ doesn’t work you encountered a problem with different data types. There’s a difference whether the number is a number or a “text” that contains the number character. If they’re not the same type the ‘Condition’ can be evaluated as ‘false’.

To get the desired result you must convert both the values to the same type. There’re two expressions to convert a ‘number’ into a number.

Use int(…) to convert whole numbers

The first one is int(…) that’ll convert a numeric value into an integer.

int(<number>)

Note: <…> is a placeholder, replace it including the < and >.

But it must be a whole number with no decimal places. Once you try to convert a decimal number into integer the action will fail.

Power Automate condition false numbers

As such the int(…) expression is a good solution only when you’re 100% sure that the number won’t have any decimal places, e.g. when working with a date.

Use float(…) to convert decimal numbers

If your number can contain also decimal places, use the float(…) expression. This expression is more generic as it doesn’t care about the number format. If it’s a whole number – fine; if it’s a decimal number – also fine.

float(<number>)

Note: <…> is a placeholder, replace it including the < and >.

Power Automate condition false numbers

Once you have the numbers in the same format it should evaluate the conditions correctly.

Summary

When your Power Automate condition always returns ‘false’, even though you can see that the numbers are the same, try to play with the data type. There’s a chance that one of the numbers is a text, not a number, and Power Automate doesn’t like that. Take both sides of the condition and convert them into the same data type. If they’re whole numbers, you can use the int(…) expression, but once decimal numbers come into play you’ll have to use float(…).


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Why the condition is false for the same numbers (Power Automate) appeared first on Let's POWER Automate.

Run ‘For selected item’ flow from non-default environment (Power Automate)

“I can’t run my Power Automate flow in the item context menu, could the reason be that it’s on a non-default environment?”


When you use the ‘For selected item’ trigger in your flow, you’re very limited by the location of the flow. It must be in the Default environment of your organisation, otherwise it won’t connect to SharePoint, yet it’s not wise to have all the flows in the default environment. Is there a way to bypass this limitation? To manually start flows on a selected item even from non-default environments?

You’ll have to use a different trigger

There’s no way to add such flow to the list context menu. But if you combine a few pieces of functionality you can achieve the same result.

Add a column and a button to the list

Firstly, add a new column to your list, e.g. Yes/No column called “RunFlow”. This column will tell the flow whether it should start or not.

Since you don’t want users to check this checkbox manually, you should allow them to do it with a button.

Not only can you trigger a flow, you can also update a column using the JSON column formatting. The piece of code to do that is as below.

  "customRowAction": {
    "action": "setValue",
    "actionInput": {
      "<columnInternalName>": "<value>"
    }
  }

In this example, when working with the Yes/No column “RunFlow”, it’ll be:

  "customRowAction": {
    "action": "setValue",
    "actionInput": {
      "RunFlow": 1
    }
  }

Putting the whole JSON code together that’ll also hide the button once the flow is started:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Run flow",
  "style": {
    "display": "=if(@currentField != true,'inherit', 'none')"
  },
  "customRowAction": {
    "action": "setValue",
    "actionInput": {
      "RunFlow": 1
    }
  }
}
Power Automate run item non-default environment

Click on such button will set the value in the RunFlow column to Yes. But that’s only the first part, it won’t trigger the flow yet.

Use a different trigger with a trigger condition

The second step is to use the trigger “When an item is created or modified” instead of “For selected item”. Automatically started flows will work fine from any environment, you just have to block it from running on every update. The flow should start only when the “RunFlow” column was set to Yes – a job for a trigger condition.

@equals(triggerOutputs()?['body/RunFlow'], true)

Once implemented, the flow will start only when users click the button.

Summary

If you want to run a manually started Power Automate on a SharePoint item, but the flow is in a non-default environment, you’ll have to use a workaround. A combination of a new column in the list, JSON formatting on that column to create updating button, and a trigger condition will do the trick. From users perspective it won’t make any difference (if you use buttons to start flows), but the flow can be separated in its own environment.

Just don’t forget to set the column value back to No in the flow if users should be able to start the flow repeatedly.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Run ‘For selected item’ flow from non-default environment (Power Automate) appeared first on Let's POWER Automate.

Hide button in SharePoint list after Power Automate flow started

“I added the button to start a Power Automate flow, but users keep pressing it over and over again, how can I hide it after the flow was started?”


The previous post explained how to add a button to SharePoint list/library to manually trigger a flow. But such button will be visible all the time and users can click on it over and over again. Multiple clicks = multiple flow runs. That’s why you should extend the JSON code a bit – hide the button after the first click, after the flow was started. And this post will show you how.

It’s also worth mentioning that the solution is not limited to hiding a button. You can use the same approach to hide (not disable) any column value based on another column. But for now let’s continue with the button example.

Hiding a column value

Hiding is done by adding a “style” and “display” properties to the JSON code as in the example with hyperlinks.

  "style": {
    "display": "=if(@currentField == '', 'none', 'inherit')"
  }

There’s a condition checking value of a column, and depending on the result it’ll set the “display” property to ‘none’ (hide) or ‘inherit’ (show).

That means you’ll need an extra column with the information whether a user already started a flow. If you’re building an approval flow you can use a status column, e.g. if ApprovalStatus = ‘Not started’.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Start flow",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"2c5dfcb2-aa4e-4cfd-9baf-2485225b1fa4\"}"
  },
  "style": {
    "display": "=if([$ApprovalStatus] == 'Not started', 'inherit', 'none')"
  }
}

Note: You must always use the column internal name in the JSON code!

Power Automate hide button flow started

If there’s no status to check you can use also a checkbox. With a small adjustment show the button only if the checkbox is not ‘true’.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Start flow",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"2c5dfcb2-aa4e-4cfd-9baf-2485225b1fa4\"}"
  },
  "style": {
    "display": "=if([$FlowDidRun] != true, 'inherit', 'none')"
  }
}
Power Automate hide button flow started

IMPORTANT: you must always check the checkbox or change the status as the first action in the flow! JSON button can do only 1 action, and this one will trigger the flow…

Summary

If you use a button to start Power Automate flow, you should always hide it once the flow is started. You shouldn’t let user run the flow multiple times, not sure whether the flow already runs. Show them the button only when needed and hide it during the first flow run by updating the ‘control’ column.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Hide button in SharePoint list after Power Automate flow started appeared first on Let's POWER Automate.

Add button to start Power Automate flow from SharePoint list

“I’d like to make triggering a Power Automate flow as simple as possible for the users, is there a way to add e.g. a button to start a flow directly from the list view?”


If you use manually started flows, they’re probably started on an item or a document. Users select the item/document, click on the 3 dots -> Automate -> run a flow. But having even these 3 clicks might be confusing for some users, especially if they don’t use flows very often. There must be an easier, more direct way to start a flow!

And there is one, by adding a button directly to the view!

Use JSON formatting to add the button

There’re many possibilities when using JSON to format a SharePoint column. The older posts showed you how to calculate with today’s date or build a hyperlink, this time it’ll show you how to build a button to start a flow.

Since the button will be in a column, it’s a good start to create one, e.g. a Single line of text column ‘StartFlow’.

Click on the column name and navigate through ‘Column settings’ to ‘Format this column’…

…into the ‘Advanced mode’. That’s where all the magic happens.

The JSON below will add the most basic button in that column.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Start flow",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"2c5dfcb2-aa4e-4cfd-9baf-2485225b1fa4\"}"
  }
}

But there’re two parts to modify, one that’s optional and one that’s mandatory to change.

The optional one is the wording on the button in the “txtContent” parameter. You can replace it with a few words on the specific flow, or keep just “Start flow” in there.

Power Automate list start flow button

The second part, the one that’s mandatory to change, is the flow id. You must tell the button what flow it should start, and that’s done by the flow unique id.

Power Automate list start flow button

Open the flow details page and check the url, this id is between the /flows/ and /details part.

Power Automate list start flow button

Copy/paste it into the JSON and save it.

And that’s it, you just created a button that’ll start a flow on a single click.

Summary

When using manually started flows, you might want to make the process as simple as possible for the users. While it’s possible to start Power Automate flow from the item/document context menu, it’s much easier to add a button to the list. Users go to the list, click a single button, and the flow will do the rest. And since it’s done using JSON formatting, you can extend it by other functionality, e.g. hide it once the flow is started, but that’s a topic for another post.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Add button to start Power Automate flow from SharePoint list appeared first on Let's POWER Automate.

Trigger Power Automate flow on a specific working day (up to 5th)

“Can I apply the ‘first working day’ solution also to another specific day, e.g. trigger Power Automate flow on the 4th working day?”


The previous post described how to trigger a Power Automate flow on the first working day in a month, but what if you want a different day? If it shouldn’t be the first day as it’s often busy but a later day, e.g. the 4th day in a month? Can the solution be adjusted? How?

Note: this solution won’t skip holidays as I’m not aware of any way to check holidays before triggering a flow. It’ll also work only up to the 5th working day including max. 1 weekend.

The idea stays the same

The logic behind the trigger condition stays the same – if the day is in a weekday, trigger the flow. If it’s Saturday or Sunday, wait until the next Monday.

Power Automate trigger specific working day

Change the number for date

The only difference from the original article is in the numbers that identify the date.

and(equals(int(utcNow('dd')),<whichDay>),not(equals(dayOfWeek(utcNow(),6))),not(equals(dayOfWeek(utcNow(),0))))

To send it on the 4th day:

and(equals(int(utcNow('dd')),4),not(equals(dayOfWeek(utcNow(),6))),not(equals(dayOfWeek(utcNow(),0))))

Change it also for Sundays…

The same applies also to the conditions when the date was Saturday or Sunday – you must increment the date. If the day ends up being a Sunday, you want to send it on the following Monday, the planned date + 1 day.

and(equals(int(utcNow('dd')),<whichDay+1>),equals(dayOfWeek(utcNow(),1)))

For the 4th day it’ll be 5, e.g.

and(equals(int(utcNow('dd')),5),equals(dayOfWeek(utcNow(),1)))

… and for Saturdays

If it takes 1 extra day for Sundays, for Saturdays it takes 2. Take again the day number, and this time increment it by 2.

and(equals(int(utcNow('dd')),<whichDay+2>),equals(dayOfWeek(utcNow(),1)))

To follow with the 4th day example, the number will be 6 this time.

and(equals(int(utcNow('dd')),6),equals(dayOfWeek(utcNow(),1)))

Put it all together

All that’s left is to put all the conditions together in a single trigger condition.

@or(
   and(equals(int(utcNow('dd')),<whichDay>),not(equals(dayOfWeek(utcNow(),6))),not(equals(dayOfWeek(utcNow(),0)))),
   and(equals(int(utcNow('dd')),<whichDay+1>),equals(dayOfWeek(utcNow(),1))),
   and(equals(int(utcNow('dd')),<whichDay+2>),equals(dayOfWeek(utcNow(),1)))
)

Summary

If you want to trigger Power Automate on a specific working day, you have to use the various dates involved. The first one is the actual day, what’s the default scenario if it’s during the workweek. The second one is the date+1 for situations when the original date ends up being Sunday. And the last one is the date+2 to cover for Saturdays. Once you add these 3 numbers in the trigger condition you should be able to trigger the flow on any specific day working day in a month.

But don’t forget that this solution will work only for the 1st 5 working in a month as it includes only 1 weekend! A generic solution would look similar to this post, which I might cover in the future.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Trigger Power Automate flow on a specific working day (up to 5th) appeared first on Let's POWER Automate.

Trigger Power Automate flow on the first working day in a month

“Is there a way to trigger Power Automate flow only once a month on the first working day, no matter what day it is?”


There’re already posts on trigger a flow on a specific day in a specific week in a month, or by the end of a month. What about another alternative in the form of a first weekday in a month? If the 1st is a weekday, send in on that day, but if it’s Saturday or Sunday, wait for Monday.

Start from 1st

The easiest situation would be if the 1st is already a weekday. You don’t have to evaluate anything, you just run the flow. Let’s add it as the first condition, and to make it shorter let’s reverse it – it’s the 1st day and it’s not Saturday nor Sunday.

Firstly, check that the day part from today’s date is 1.

equals(int(utcNow('dd')),1)

Secondly, check that the day is not Saturday.

not(equals(dayOfWeek(utcNow(),6)))

Thirdly, check that the day is not Sunday.

not(equals(dayOfWeek(utcNow(),0)))

Now combine it all together using the and(…) expression.

and(equals(int(utcNow('dd')),1),not(equals(dayOfWeek(utcNow(),6))),not(equals(dayOfWeek(utcNow(),0))))

Send it on 2nd if 1st was Sunday

The other situation that could happen is that 1st is on Sunday, therefore, the flow should be triggered on Monday.

Check if the day part of the date is 2.

equals(int(utcNow('dd')),2)

And at the same time the day is Monday, otherwise it’d trigger on every 2nd day.

equals(dayOfWeek(utcNow(),1)

Again, put it together using the and(…) expression.

and(equals(int(utcNow('dd')),2),equals(dayOfWeek(utcNow(),1)))

Send it on 3rd if 1st was Saturday

The last situation is if the 1st day was Saturday, in that case you want to send it on Monday 3rd. Following the same logic as before, check that the day is 3…

equals(int(utcNow('dd')),3)

…and the day is Monday.

equals(dayOfWeek(utcNow(),1)

Combining them together:

and(equals(int(utcNow('dd')),3),equals(dayOfWeek(utcNow(),1)))

Build the final trigger conditions

The conditions above covered all situations:

  1. If it’s the 1st day and it’s not Saturday and Sunday, run the flow
  2. If it’s the 2nd day and it’s Monday, run the flow as 1st day was Sunday
  3. If it’s the 3rd day and it’s Monday, run the flow as 1st day was Saturday

This time you must connect them with the OR(…) expression as it must always fit into one of the options:

or(
   and(equals(int(utcNow('dd')),1),not(equals(dayOfWeek(utcNow(),6))),not(equals(dayOfWeek(utcNow(),0)))),
   and(equals(int(utcNow('dd')),2),equals(dayOfWeek(utcNow(),1))),
   and(equals(int(utcNow('dd')),3),equals(dayOfWeek(utcNow(),1)))
)

Add the @ before the expression and use it as a trigger condition.

Power Automate trigger first working day

Summary

You can trigger Power Automate flow on the first working day in a month if you check all the possible situations. If the 1st day is a working day, trigger the flow right away. The only situations when it should be delayed is if it’s Saturday or Sunday, in that situations you want to send it on Monday. Either Monday the 2nd or Monday the 3rd.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

The post Trigger Power Automate flow on the first working day in a month appeared first on Let's POWER Automate.

❌
❌