Developer forum

Forum » Development » notification subscriber - New NewsV2 item

notification subscriber - New NewsV2 item

Jais Edelmann
Reply

Hey is there any notification subscriber for when an editor creates a new news item? I would like to do some code when someone posts a new news item.

 

Also on a side note, the if statements in templates, is it possible in the newsv2 list to check if a value is longer then 1? if cant seem to get it to work if defined just outputs my content regardless of weather the tag is string empty or has something in it.


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Jais,

 

Take a look at the Dynamicweb templates for Visual Studio. In the News V2 Category you find a News Item Saved notification that may do do what you need:

 

[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Modules.News.Notifications.ItemSaved)]
public class NewsV2ItemSavedObserver1 : Dynamicweb.Extensibility.NotificationSubscriber
{
  public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
  {
    if (args == null)
      return;

    if (!(args is Dynamicweb.Modules.News.Extensibility.NewsItemNotificationArgs))
      return;

    Dynamicweb.Modules.News.Extensibility.NewsItemNotificationArgs news = (Dynamicweb.Modules.News.Extensibility.NewsItemNotificationArgs)args;

    //news.Item.NewsAuthor = "me";
    //news.Item.Save();
  }
}

 

Cheers,

Imar

 

 

 
Morten Bengtson
Reply

Hi Jais,

There is a notification for when a news item is saved - Dynamicweb.Modules.News.Notifications.ItemSaved

However, it's not only triggered when new items are created, but also when existing items are updated. So you might want to check the NewsCreatedDate or mark the item in some way.

I'm not sure about what can cause the issue you describe regarding If Defined. Can you post the HTML with If Defined here?

BR.

Morten

 

 
Morten Bengtson
Reply
Crap! I'm just too slow :)
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

But only by a few seconds ;-) And you added a lot of value by saying the notification gets called on Update as well....

Imar

 
Jais Edelmann
Reply
Agreed both answers awesome, thanks for the help guys :)

 

You must be logged in to post in the forum