cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PhilFancy
Advocate I
Advocate I

SharePoint News to Teams - How to ensure just one run per News?

Hi,

 

I have several flows being triggered by SharePoint News and posting to Teams channel when a news was published. 

Trigger: SharePoint: When file is created or modified in SitePages
with trigger condition @equals(triggerBody()?['PromotedState'], 2)

 

This works great and runs only for news and not for regular pages. 

 

The trigger "created or modified" is necessary because some news are posted as news directly, others become news from existing regular pages. 

 

The problem:

If someone posts a news the flow works as expected and posts to Teams. But if the user tries to correct a typo 3 mins afterwards the flow starts a second time. 

 

Does anyone see a way how to avoid a flow being started for an item a second time after it was started once? 
I just can imagine creating a "flows that ran" list that gets filled with the item IDs that already had a Teams post and check this every run to avoid doing a second post in Teams for one news. 

 

Am looking forward to hearing your ideas! 

 

Phil

 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Dual Super User
Dual Super User

Hi @PhilFancy,

 

You could add a boolean field to the site pages library. When you post the first message to teams you could set that column to yes. In your trigger condition you could check if that field isn't set to yes.


Below is an example of that approach.

 

1. Create a SentToTeams boolean field in the Site Page Library.

 

senttoteamsboolean.png

 

2. Modify your trigger condition expression and include the check for the SentToTeams field.

 

@and(equals(triggerBody()?['PromotedState'], 2), not(equals(triggerOutputs()?['body/SentToTeams'], 'Yes')))

 

 

3. Add an update file properties action. Make sure you set the SentToTeams value to Yes.

 

updatesenttoteamsproperty.png

View solution in original post

2 REPLIES 2
Expiscornovus
Dual Super User
Dual Super User

Hi @PhilFancy,

 

You could add a boolean field to the site pages library. When you post the first message to teams you could set that column to yes. In your trigger condition you could check if that field isn't set to yes.


Below is an example of that approach.

 

1. Create a SentToTeams boolean field in the Site Page Library.

 

senttoteamsboolean.png

 

2. Modify your trigger condition expression and include the check for the SentToTeams field.

 

@and(equals(triggerBody()?['PromotedState'], 2), not(equals(triggerOutputs()?['body/SentToTeams'], 'Yes')))

 

 

3. Add an update file properties action. Make sure you set the SentToTeams value to Yes.

 

updatesenttoteamsproperty.png

Hi @Expiscornovus 

 

Thank you for that great approach - I am confused I did not see this as a possible solution *facepalm* 🙂

 

The approach worked like a charm but needed to do a little change!

 

First I used a boolean column as recommended and used your trigger condition. It kept shooting Teams messages.

@and(equals(triggerBody()?['PromotedState'], 2), not(equals(triggerOutputs()?['body/SentToTeams'], 'Yes')))


So I tried 'True' instead of 'Yes', but with no success. The flows keep starting.

@and(equals(triggerBody()?['PromotedState'], 2), not(equals(triggerOutputs()?['body/SentToTeams'], 'True')))

 

So in the end I created a new single line of text column "TeamsInfo" and just put a 1 in there when the flow ran. This is what worked great. This is the condition working for me:

 

@and(equals(triggerBody()?['PromotedState'], 2), not(equals(triggerOutputs()?['body/TeamsInfo'], '1')))

 

Thank you for your help and for this great approach. Will add this to all of our News-To-Teams-Flows! 

 

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,743)