Can I access the notification settings for a node through the api?
Hi all,
I'm working on some custom notification functionality. What I'd like to be able to do is to work out from a given node which users have 'signed up' for notification for changes to that node.
Put another way, I want to get the list of users who would be notified of a particular event (e.g. publish) of a given node, using the API (i.e. in a .NET user control).
Notifications-via-API are actually quite hard to work with, I've tried it. Compared to other aspects of Umbraco it's actually quite closed.
The class umbraco.cms.businesslogic.workflow.Notification is the only way I've found to interact with it, but the GetNotifications method actually sends the notification.
Your other option is umbraco.BusinessLogic.User which has a GetNotifications method does return a string which probably has some information of use...
Turns out in v4.1 you can use the GetNodeNotifications method. Here's a code snippet to get the notifications for a given node. Note that you need to check the letter to work out which action has been subscribed to (unless you want all users who have subscribed for notifications for any action on the node). See http://our.umbraco.org/projects/standard-values-in-umbraco/bug-reports/8204-Notifications-issue for a list of letters used by Umbraco. Here's the code to get the users. Here is the code:
List<Notification> notifications = (List<Notification>)Notification.GetNodeNotifications(new CMSNode(nodeId)); List<User> usersToNotify = new List<User>();
foreach (Notification notification in notifications) { // Check that the notification is for publish or send to publish if (notification.ActionId == 'U' || notification.ActionId == 'H' || notification.ActionId == 'B') { User u = new User(notification.UserId); usersToNotify.Add(u); } } // now do something with your list of users
For anyone who's trying to achieve something similar, it turns out that the GetNotifications() call is not recursive, so you need to recurse the tree yourself in order to get any notifications that cascade down from parent nodes.
Here's the code I've used to create a comma-separated list of email addresses to send notifications to:
CMSNode n = new CMSNode(nodeId);
List<Notification> notifications = new List<Notification>();
GetNotifications(n, ref notifications);
foreach (Notification notification in notifications)
{
// Check that the notification is for publish or send to publish
Can I access the notification settings for a node through the api?
Hi all,
I'm working on some custom notification functionality. What I'd like to be able to do is to work out from a given node which users have 'signed up' for notification for changes to that node.
Put another way, I want to get the list of users who would be notified of a particular event (e.g. publish) of a given node, using the API (i.e. in a .NET user control).
Is this possible?
Cheers!
David
Notifications-via-API are actually quite hard to work with, I've tried it. Compared to other aspects of Umbraco it's actually quite closed.
The class umbraco.cms.businesslogic.workflow.Notification is the only way I've found to interact with it, but the GetNotifications method actually sends the notification.
Your other option is umbraco.BusinessLogic.User which has a GetNotifications method does return a string which probably has some information of use...
Thanks for the info @slace, I'll have a dig around in the source and see what I can find.
Turns out in v4.1 you can use the GetNodeNotifications method. Here's a code snippet to get the notifications for a given node. Note that you need to check the letter to work out which action has been subscribed to (unless you want all users who have subscribed for notifications for any action on the node). See http://our.umbraco.org/projects/standard-values-in-umbraco/bug-reports/8204-Notifications-issue for a list of letters used by Umbraco. Here's the code to get the users. Here is the code:
In 4.1 I've updated the notifications API to be 'consistent' with the rest.
For in depth examples of all of the data APIs for 4.1, you can have a look at the source in the project Umbraco.Test
Hi all,
For anyone who's trying to achieve something similar, it turns out that the GetNotifications() call is not recursive, so you need to recurse the tree yourself in order to get any notifications that cascade down from parent nodes.
Here's the code I've used to create a comma-separated list of email addresses to send notifications to:
And this is the recursive function that creates the list of notifications for all nodes from the current one up the tree:
is working on a reply...