November 20, 2024

Power Automate: SharePoint – When a file is created (properties only) Trigger

The “When a file is created (properties only)” trigger is an excellent way to control files by automating the actions that deal with them.

Today we’ll look at how it works and how to use it efficiently.

Where to find it?

To find it, you can search for the “When a file is created (properties only)” action or go to “SharePoint.”

Select “When a file is created (properties only)” from the list.

Here’s what it looks like.

Pro Tip Power Automate tends to save the most common triggers in the main screen, so check there before going through the full hierarchy. Also, you can use the search to find it quickly.

Let’s check how to use it.

Usage

The trigger requires the following information:

  1. Site address – where to look for new files
  2. Library Name – since we can have multiple libraries, we need to define which one we’ll look at.
  3. Folder – The folder is optional since you can define that you want to catch all files created in the document library.
Please remember that the Flow will trigger for each file created so you’re always sure that you have a single file to look per run.

Here’s an example:

Let’s upload a new Document.docx (ok, I’m not the most creative person when it comes to naming things) and see what happens:

Notice that we uploaded the file into the “Attachment” folder, and Flow catches the file creation. Another essential thing to consider is right in the trigger’s name. Power Automate will only return the file’s properties, so if you want to get the file contents, you must use the “Get file content” Action.

Outputs

The trigger returns a lot of information in a JSON format, although the conversion from JSON is done automatically for you. Here’s an example:

{
  "headers": {
    <redacted>
  },
  "body": {
    "@odata.etag": "\"2\"",
    "ItemInternalId": "95",
    "ID": 95,
    "Modified": "2021-11-04T11:15:03Z",
    "Editor": {
      "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
      "Claims": "i:0#.f|membership|manuel@manueltgomes.com",
      "DisplayName": "Manuel Gomes",
      "Email": "manuel@manueltgomes.com",
      "Picture": "https://manueltgomescom.sharepoint.com/sites/Test/_layouts/15/UserPhoto.aspx?Size=L&AccountName=manuel@manueltgomes.com",
      "Department": "",
      "JobTitle": ""
    },
    "Editor#Claims": "i:0#.f|membership|manuel@manueltgomes.com",
    "Created": "2021-11-04T11:15:01Z",
    "Author": {
      "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
      "Claims": "i:0#.f|membership|manuel@manueltgomes.com",
      "DisplayName": "Manuel Gomes",
      "Email": "manuel@manueltgomes.com",
      "Picture": "https://manueltgomescom.sharepoint.com/sites/Test/_layouts/15/UserPhoto.aspx?Size=L&AccountName=manuel@manueltgomes.com",
      "Department": null,
      "JobTitle": null
    },
    "Author#Claims": "i:0#.f|membership|manuel@manueltgomes.com",
    "OData__DisplayName": "",
    "{Identifier}": "Shared%2bDocuments%252fAttachment%252fDocument1.docx",
    "{IsFolder}": false,
    "{Thumbnail}": <redacted>,
    "{Link}": "https://manueltgomescom.sharepoint.com/sites/Test/Shared%20Documents/Attachment/Document1.docx?d=w177b5536d74b42c39b817d9801342d10",
    "{Name}": "Document1",
    "{FilenameWithExtension}": "Document1.docx",
    "{Path}": "Shared Documents/Attachment/",
    "{FullPath}": "Shared Documents/Attachment/Document1.docx",
    "{IsCheckedOut}": false,
    "{VersionNumber}": "1.0",
    "{TriggerWindowStartToken}": "MTszOzNlZDk2NGQzLTk1YzMtNGJlY1y04M2E3LWJjOGEyOTk3NmJlYTs2zc3MTYyMTI3zNTUxMzAwMDA7NTg4MDE1NjY3",
    "{TriggerWindowEndToken}": "MTszOzNlZDk2NGQzLTk1YzMtNGJlY1y04M2E3LWJjOGEyOTk3NmJlYTs2zc3MTYyMTI3zNTUxMzAwMDA7NTg4MDE1NjY3"
  }
}

There’s a lot of information, but some are pretty useful. First, look at the properties and some tricks to improve your data.

Identifier vs. ID

The file identifier is used to fetch things like its content and is required in other actions, like the “Get file content,” for example. Notice that we have the “Identifier” and the “ID.” They serve different purposes. The “Identifier” is used in the actions to fetch the file itself.

To understand why the ID is, we need to understand that files in SharePoint are stored as items in a list. We see them as “files,” but we can add additional properties. Let’s open the list and see how to add the “ID.

Pick “ID”

You’ll see it in the list.

So think of it as follows:

  1. The “Identifier” is the file itself, where we can get the file size, path, and contents, for example.
  2. The “ID” is the file’s list properties, like the modified date and other columns we add to augment the file’s information.

Properties vs. Columns

Files have properties like the file size and path, but you can add more columns to augment the file’s information. For example, if you want to have a column with an approval status, you do the following:

Add the options.

Here’s what it looks like.

You can do this to any document library and have many more information associated with files. However, please remember to use the “ID” and not the “Identifier to edit this information.”

Limitations

You can’t access files in a shared library.

Recommendations

Here are some things to keep in mind.

The folder is optional but think about it.

SharePoint document libraries can be pretty busy, and Power Automate will trigger a lot depending on the files created. Limit the folders you want to look at as much as possible, but if not possible, plan for what happens when the Flow triggers a lot, like quotas, for example.

Never generate the ID or Identifier.

I always recommend against generating the ID. Although getting the ID by encoding the special characters is possible, it’s pretty error-prone if you know the path. For example, if Microsoft changes something in Power Automate, you’ll get into trouble, but if you use the IDs from other actions, your Flows become future-proof of any changes.

Name it correctly

The name is super important since we can get the trigger from anywhere and with anything. Always build the name so that other people can understand what you are using without opening the action and checking the details.

Always add a comment.

Adding a comment will also help avoid mistakes. Indicate your expectations, why the Flow should be triggered, and the data used. It’s essential to enable faster debugging when something goes wrong.

Back to the Power Automate Trigger Reference.

Photo by Henry & Co. on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

6 thoughts on “Power Automate: SharePoint – When a file is created (properties only) Trigger

  1. Hi Manuel,
    Every week I have to look at several folders and check in them if a file has been created or modified.
    Do you have any solution for this?

    Regards,
    JM

    1. Hi,

      Here’s the high-level Flow. If you have questions in any step, please let me know, and I’ll try to help you.

      It depends on where the folders are. If they are in the same folder, like (/folder to check/):
      1. First start with a Recurrence Trigger with the time you want to trigger it.
      2. You can use a list folder action where you’ll get all files and folders.
      3. Use an Apply to Each action to go through all folders. Since the previous step will give you all files, you should filter if they are folders or not. The previous action will return a value that you use the condition action.
      4. Use the list folder action again to get the files inside that folder.
      5. For the previous action, you can use steps 3 and 4 but filter only the files you want to check.
      6. Now, we need to check if the file was changed or not. You can use the “Get file metadata” action that will provide you the date that the file was last modified. If it’s after the last time the Flow ran, you have a file that fits your conditions. You can then perform the actions that you feel appropriate here.

      If they are in multiple places (/folder to check 1/ and /folder to check 2/), then you cannot use the previous steps 2 and 3. You need multiple steps 4 one for each folder you want to check. Then you can replicate the following steps to get the information you need.

      I know there are some steps but start slow you’ll be able to do it.

      I hope this helps you!

      Cheers

  2. Thanks Manuel, I think this is the third or fourth time where one of your articles has stopped me from tearing my hair out with Power Automate. On this occasion, it was because a Sharepoint trigger was giving me the ID (number) but what the Excel connector wanted was the Identifier (relative filepath) that would need to be obtained through another Sharepoint call! Who on earth decided to give two attributes the names ID and Identifier without them being interchangable?!

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon