Forum Discussion

RJDBakker's avatar
RJDBakker
Copper Contributor
Feb 28, 2022

How to trigger a flow based on change in title column of documentset?

I am trying to trigger a flow only when the columns (metadata) of a documentset is changing.

My documentset consists of several columns and standard folders.
For business reasons I want to trigger a Power Automate flow only when a certain column is changed.

 

The Tigger condition I use for ‘when an item or file is modified’ is:

@equals(triggerBody()?['{ContentType}']?['Id'], '0x0120D52000C5A1E6112625E241BF1968469A689EB7001463D6ACDB134C4CB9D00A39A6072585')

 

The Id is from the Document set content type.

 

The problem is that the flow is also triggered when a document or folder within the documentset has changed. I am guessing that this is due to the fact, that changes within the documentset also count as a change of the documentset itself.

 

When looking at the output; I see the Id of the documentset is the item that is changed:

My question:

Is it possible to start a trigger for a flow only when a certain metadata field is changing?

In my case this is the ‘title field’.

 

  • RJDBakker 

    In this case, have you tried to add the additional, required condition within the triggers` settings?

    @and(
         NOT(equals(
                triggerBody()?['Title'],
                triggerBody()?['{Name}']
                   )
           )
         ,
         equals(
            triggerBody()?['{ContentType}']?['Id'],
            '0x0123456789abcdefghijk9876543210kjihgfedcba'
              )
         )

     

  • Micca0815's avatar
    Micca0815
    Iron Contributor

    RJDBakker 
    You could accomplish this with an additional action and a condition after your trigger.
    Look for the SharePoint connector action 'Get changes for an item or a file (properties only)'.
    This way you get the columns which have been changed by comparing them to the previous version ('Since' expression below).

    Dynamically link the site and the library from the triggers properties:

    • site: trigger()?['inputs']?['parameters']?['dataset']
    • library: trigger()?['inputs']?['parameters']?['table']
    • ID: triggerOutputs()?['body/ID']
    • Since : sub(int(triggerOutputs()?['body/{VersionNumber}']),1)

      Afterwards use a condition to check if the title column returns true for any column change:

      outputs('Get_changes_for_an_item_or_a_file_(properties_only)')?['body/ColumnHasChanged/Title']

      This would not avoid the additional Flow run, but at least any action could depend on a certain column change only.

    • RJDBakker's avatar
      RJDBakker
      Copper Contributor

      Micca0815 

       

      Thank you for your reply

      Your suggestion is much useful.

      But I am still looking for a way to not trigger the flow at all.
      This is because of the fact that it will otherwise trigger 1000’s of time every week.

      Documents are changed and uploaded constantly. The metadata field will probably change a very few times during the lifespan of the document set.

       

      At this point I think it is not possible to prevent the flow from starting based on the ‘only run when the title changes’ trigger and have to look for a more user unfriendly alternative.

       

      The root cause of my problem is that the ‘filename’ field cannot be changed natively from a PowerApps form. During the initializing of the Document set I trigger a flow that copies the filename field to the title field. After that, the user has the possibility to change the title.

       

      My idea was, that the title field then again would be copied to the filename field automatically.

      • Micca0815's avatar
        Micca0815
        Iron Contributor

        RJDBakker 

        In this case, have you tried to add the additional, required condition within the triggers` settings?

        @and(
             NOT(equals(
                    triggerBody()?['Title'],
                    triggerBody()?['{Name}']
                       )
               )
             ,
             equals(
                triggerBody()?['{ContentType}']?['Id'],
                '0x0123456789abcdefghijk9876543210kjihgfedcba'
                  )
             )

         

Resources