Developer forum

Forum » Development » Args is empty on ItemNotification.Saved

Args is empty on ItemNotification.Saved

Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Hi,

I'm working on a notification subscriber, in order to update a certain itemfield, whenever a new page of a certain itemtype is created.

I have been using the code below, but when I try to get information about the item saved from the args, it is always empty (null)

Am I subscribing to the wrong kind of notification? I've also tried subscribing to the Dynamicweb.Notifications.Standard.Page.Saved notification, but with the same result.

Best regards
Kurt Moskjaer Andersen

[Subscribe(Dynamicweb.Notifications.ItemNotification.Saved)]
 
 public class ItemSaved : NotificationSubscriber
 {
     public override void OnNotify(string notification, NotificationArgs args)
     {
         if (args == null)
             return;
          var pna = (Dynamicweb.Notifications.ItemNotification.ItemArgs)args;
}
}

Replies

 
Nicolai Pedersen
Reply

Hi Kurt

This one should do the trick for item based pages: https://doc.dynamicweb.com/api/html/01031cef-7c8e-8209-6ead-2fa57d3bb6a1.htm

In the example above you should be able to get hold of the item:

pna.Target.Item

And if you use the OnBeforeSave instead - you should be able to just change the value of the item attached to the page object, and DW wills ave your updated value for you.

BR Nicolai

 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Hi Nicolai,

Even though I'm using the exact same code as you and output the value of pna.Target.ID or pna.Target.Item, it still reports the pna as null.

Best regards
Kurt

 
Nicolai Pedersen
Reply

Hi Kurt

Sounds very strange. When you say "It reports" as null. What is "it"?

And can I see you full code?

BR Nicolai

 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Hi Nicolai,

Well, I've run a debug on my local maschine, by adding a breakpoint on the variable pna and outputs the value to the console.

The value of the pna.Target.ID or pna.Target.Item is always either null or throws an exception, whenever I create a new page in Dynamicweb.

My code is listed below:

namespace VM.Subscribers
{
    [Subscribe(Dynamicweb.Notifications.Standard.Page.Saved)]
    public class PageSavedObserver : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            if (args == null)
                return;
 
            var pna = (Dynamicweb.Notifications.Standard.Page.PageNotificationArgs)args;
            //Pass page Id to the notification e-mail
            var emailBody = string.Format("The page (ID:{0}) has been saved.", pna.Target.Item);
        }
    }
}
 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

As a comment, I'm running on DW 9.2.15

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Kurt

Please upgrade to 9.3 then. All of this has changed quite substantial since 9.2 - so please check if the issues is still there on 9.3. If it is a bug, it will be fixed in 9.3+ branch only.

BR Nicolai

Votes for this answer: 1
 
Kurt Moskjær Andersen
Kurt Moskjær Andersen
Reply

Hi Nicolai,

I closed this thread a little to early, as the error also occours in the latest DW version 9.3.11.

I'm using the code example at https://doc.dynamicweb.com/api/html/01031cef-7c8e-8209-6ead-2fa57d3bb6a1.htm as inspiration.

Best regards
Kurt

 

You must be logged in to post in the forum