Power automate ファイル更新 トリガー

I'm using the OneDrive when a file is created trigger in my flow. I want to set a trigger condition that will only trigger if the file type is .xlsx

I tried the following condition: @contains(triggerOutputs()?['headers/x-ms-file-name-encoded'], 'xlsx')

I get the following error: InvalidTemplate. Unable to process template language expressions for trigger 'When_a_file_is_created' at line '1' and column '37225': 'The template language function 'endswith' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#endswith for usage details.'.

I did some research on-line and it appears to be due to the OneDrive dynamic selector "File name" being encoded, but I wasn't able to find any solutions for working around this issue.

Any help is greatly appreciated

Thanks

asked Jun 22 at 13:48

Power automate ファイル更新 トリガー

You can use the base64tostring function to turn it into a readable string.

Try an trigger condition expression like below

@endswith(base64tostring(triggerOutputs()?['headers/x-ms-file-name-encoded']), '.xlsx')

answered Jul 19 at 21:00

Power automate ファイル更新 トリガー

Today’s question comes from Echo and asks me the following:

Problem Scenario: When file is created in SharePoint folder named “Attachment”, extract the file and create item in SharePoint list”

User Process: usually the users are creating new excel file and save it in the SharePoint folder named “Attachment” see the photos below.

So let’s check how to do this by deconstructing the problem further. We need to:

  1. Monitor a folder for Excel files (I cleared with her that she wanted Excel files at the end).
  2. Get the information from the Excel file (the Excels all have the same information).
  3. Update SharePoint by adding the data to the list.

Looks easy, but there are some things to consider, so let’s start.

The trigger

So we need a trigger to monitor if a file was created in a folder, and SharePoint has a trigger to do that. It’s called “When a file is created in a folder”. Although it only monitors a folder and not subfolders, it’s perfect for this example. Here’s what it looks like:

Power automate ファイル更新 トリガー

With this trigger, we can have all the file information as soon as it’s created. Now let’s look at what to do with the file.

We only want Excel files

So now that we have one file, we want to filter it so that we only have Excel files. To do that, a simple “condition” action will do the trick.

Power automate ファイル更新 トリガー

Notice two things. First, we’re getting the “content-type” of the file. Don’t try to understand what it means since the names are super obtuse and based on conventions. But here’s Excel (xlsx) file:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

And here’s the Excel (xls) file:

application/vnd.ms-excel

You can get the “Content-Type” in the list.

Power automate ファイル更新 トリガー

Another thing to notice is that in the “Condiction” action we are checking if it’s an Excel (xlsx) “OR” an Excel (xls) since it can’t be both. Please notice this when building your Flow.

Power automate ファイル更新 トリガー

Now that we have a condition, let’s fetch the data.

Fetching the data

Now that we have the Excel file, we need to get its information. But we have a problem. The “When a file is created in a folder” returns us the file’s “Identifier,” but we need the file “ID.” It isn’t apparent, but that’s how it works. So we need to do a “Get file metadata” action to get the information of the file before we can continue.

Power automate ファイル更新 トリガー

I wrote two articles (find them here and here) on how to get the information from an Excel file if you don’t know it’s path when developing the Flow. It’s not hard, and I explain it in detail, but it doesn’t make sense to duplicate the information here. Please check those two articles in case you have any questions.

The following steps are to get the information from Excel. Depending on your Excel’s complexity, you can have multiple worksheets and tables to get them all, use an “Apply to Each” action to go over each one, and then fetch the tables with that information. I included the actions so that you know what to use.

The critical part is the last action, the “List rows present in a table,” which fetches all the data you need to update SharePoint.

Adding the data

Now that you have the information from Excel, you only need to update SharePoint, by assing the items to the list. You can use the “Create item” action to do that.

The Excel and the SharePoint list don’t need to have the same structure since you can have intermediate steps to “convert” the data, but the Excel should have the information you need to insert into SharePoint.

Final thoughts

I liked this question because it’s boring to do (look at folders) and even worse to insert data, so with a few actions, you can look at a folder, parse the data and insert it. My kind of favorite Flow is simple to do and saves you dozens of hours of manual work. Thanks to Echo for submitting this question.

Have a suggestion of your own or disagree with something I said? Leave a comment or interact on Twitter and be sure to check out other Power Automate-related articles here or if you want to check other solved problems, click here.

Photo by mari lezhava on Unsplash

Power Automateのメールトリガーの条件は?

トリガー条件の設定方法.
「新しいメールが届いたとき」トリガーのメニューを開きます。.
設定をクリックします。.
トリガー条件を追加します。 トリガー条件セクションにある「+追加」をクリックします。.
トリガー条件を記入します。 じょじお ... .
完了ボタンをクリックして保存します。 ... .

Power Automateのトリガーの種類は?

Power Automateトリガーには「プッシュトリガー」と「ポーリングトリガートリガーがあります。 プッシュトリガーとポーリングトリガーでクラウドフローの動作が若干異なるので、まとめておきたいと思います。

SharePoint リスト どこ?

SharePoint Online のサイトの左メニューから「ホーム」を選択し、上部に表れる「+新規」をクリックします。 そこから「リスト」を選択すると、リストの新規作成画面に移行できます。