Trigger your flow only when a document is created from a specific content type

Be careful this might not be supported in the future, use it at your own risk!

A few days a ago, @johnnliu reminded us that in LogicApps we can specify a condition to a trigger and that we can use that in flow without having to pay flow instances. More details in the Logic App documentation. This option is available since the beginning of Logic Apps.

The thing is this option is not visible to flow users, so we must be very careful with this (you will see why later) but this can solve many issues : one of them is that peop, this le often ask me how to trigger a Flow when a document is created or modified, but only when this document is based on a specific content type…and they don’t want to pay a flow instance if the document is not based on the good content type.

Of course you can create a Flow that triggers when a document is created in a SharePoint Document library and this flow you can check the content type, but don’t forget that you have a limited number of flow instances.

Now how can we achieve this without using paid Flow instances ?

Here is my document libraries using several content types:

listct

And my goal is when a contract is created my flow must trigger, but not when I create other kinds of items.

Create a “normal” flow triggered when something is created in your document library.

flow1

Export the Flow as a package :

export

Unzip the exported package and open the flow definition file in a JSON editor

export2

Find the trigger definition and add a “Condition” statement where you can provide a Workflow definition language expression that should return true if you want the trigger to start successfully : (the condition statement is not available by default, you must create it)

export3

So basically here, I want to trigger my flow only if the content type name is ‘Contract’.

Now you need to zip everything back and you must reimport your package from Flow:

import

Let’s test this : create a document based on the Document content type and check your flow runs : you won’t see anything; actually this is not new in flow, you have “invisible & upaid” runs that you can see if you go to “see all” :

seeall

and select the Checks (no new data)

seeskipped

These are “skipped” runs : runs stopped just after the trigger (because a condition was not met), and they are free in Microsoft Flow.

If you create a Contract document, your run must be visible (this is paid from your flows quota)

Now be careful, because if you change the trigger in your flow, you will have to reinject the condition again.

Also keep in mind that what cannot be done through the Flow Designer might not be supported in the future, so again use it at your own risks!

One response to “Trigger your flow only when a document is created from a specific content type

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s