Developer forum

Forum » Development » Notifications.UserSaved - User ItemType

Notifications.UserSaved - User ItemType

Jonas Mersholm
Reply

I'm trying to use the "Notifications.UserSaved" observer to set an item-field with a value, stored in a cookie, when the user registers through the extranet.  

The user is added to a group, which states that the itemtype should be set; when registering and looking at the user in the backend, the itemtype is set correctly for that given user.

But when fetching the user from the "Notifications.UserSaved" observer, the ItemType field is "blank", although the observer states that it fires when the user HAS been saved. 

I've tried to get the user by ID aswell, but also here, the ItemType string is empty. 

 

How do i get the ItemType and ItemId from the newly created user, in the "Notifications.UserSaved" observer?

 

            var Logger = Dynamicweb.Logging.LogManager.Current.GetLogger("UserSavedObserver");

            Logger.Log("Starting a user saved observer");

            if (args == null || !(args is UserNotificationArgs))
                return;

            Logger.Log(" - Args are filled");

            UserNotificationArgs item = (UserNotificationArgs)args;

            // Fetching user.
            var ActualUser = Dynamicweb.Security.UserManagement.User.GetUserByID(item.Subject.ID); // ALSO TRIED JUST WITH "Item.Subject", same thing.

            if (ActualUser.ItemType != "Bruger")
            {
                Logger.Log("Not right itemtype: " + ActualUser.ItemType);
                return;  /// ENDS HERE AND RETURNS "ActualUser.ItemType"=""
            }

            Logger.Log(" - Item-type is Bruger");

 

Best,

Jonas


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Jonas

Attaching the item type is handled by the UI - because a user can be a member of many groups, and it is the one you choose in the UI that defines which item type that gets attached to that user. So you can basically just create the item your self and add the itemtype and itemid to the user object.

BR Nicolai

Votes for this answer: 1

 

You must be logged in to post in the forum