Forum Discussion
How to Send an Email when added a News Post in SharePoint Online site
Hi Mbryant705, sorry I realised I completely forgot to follow up on this post, so also apologies to everyone else involved in the thread.
In a very simple Flow, I can send an email notification when a news item is published. There are a couple of things to be aware of:
- Site Pages won't normally appear in the list of libraries in the trigger, therefore you need to select "Enter a custom value" and then type in Site Pages
- The published state of a document is held within a metadata field called "Promoted state". 1 = in Draft, 2 = Published. If it's a standard site page, not a news item, the Promoted state will be 0.
I can create a condition so that if the Promoted state = 2 (News Item is published) then I can send an email to the required user(s). I can alternatively use the Flow actions to send out a push notification, send a message to Teams etc however you want to get your notification out.
An example Flow is attached to this post. I hope that helps.
This works 100% however..... If for some reason i go back to an older news post and edit or republish then another email comes out. Is there a way to send out the email on promote state = 2 (original news post) But not to send out any future emails even if someone makes a change to the post?
- gfhgf870Mar 28, 2022Copper Contributor
I'm probably too late to help anyone involved in the thread, however, for future users wondering how to solve this issue, here's how I did it.
There is a metadata field known as version number.This number increments it's decimal component every time a draft is saved, the first draft will be saved as version 0.1, the next time you open the news page's draft, the auto-saves for that "session" will be saved as a version 0.2. The decimal will only go up once you save a "new" draft.
Once you publish the news article, said version number changes to 1.0, if you were to edit the published article, those changes would be saved as version 1.1 (1.2 if you save it as a draft and keep editing it later on).
If you then decide to republish the news article, its version number will update to 2.0.
As far as i've seen, the pattern keeps going on
Now back to the original question, to avoid resending emails for updated news articles we can simply add a second line to our condition that checks if the version number is exactly 1.0. This way our conditional block checks if the modified file is a published news page (thanks to the promoted state == 2 condition) AND if it's the first version being published (version == 1.0).
NOTE: The "decimal" portion of the version number doesn't act like a decimal; in practice it works more like a second index annexed by a dot.
The sequence of version numbers would go such as:
0.1 < 0.2 < 0.3 < ... < 0.11 < 0.12 < ... < 0.21 < 1.0 < 1.1 ...
I hope this helps any future lurkers. - DNaughtonJan 10, 2022Copper Contributor
Hi Matt, this is really good. I have only one issue, I have set the Promoted State to 2, but when I publish the expression result is always false. If I set it to one, then it sends an email (draft or published). I have copied your flow exactly, any ideas?
Edit: I have just checked the raw outputs and it is saying the state is 1.