[Solved] SendingContentNotification Update User Picker
o
I'm trying to set a default value to a user picker using the SendingContentNotification so the picker gets automatically populated when the user creates the content, but the picker doesn't show the user as expected. The code I'm using:
Copy code
if(notification.Content.ContentTypeAlias != Post.ModelTypeAlias)
            return;

        foreach (var variant in notification.Content.Variants)
        {
            var postAuthor = variant.Tabs.SelectMany(f => f.Properties)
                .FirstOrDefault(f => f.Alias.InvariantEquals("author"));
            
            if(variant.State != ContentSavedState.NotCreated)
                return;

            var loggedInUser = _backOfficeSecurityAccessor?.BackOfficeSecurity?.CurrentUser;
            if (loggedInUser == null) return;
            
            if (postAuthor != null)
            {
                postAuthor.Value = loggedInUser.Id;
            }
        }
If I do this with the ContentSavingNotification it works but I prefer to set the default so the Editor know that their user will be the author unless he/she change the value.
a
User pick only accepts an ID ?
dont you need the.. whats it called.. Not the guid..
Ah an UDI
I reckon it's the same for a Userpicker, but not 100% sure
o
I've tryed but GetUDI() in user gives an error saying "not supported in this entity type". Aside from that, I've checked and in this case, is the ID that is saved in the database as a value for my property I don't know if the problem is specific just to the IUser type
I've tried with the value = id (it works when saving, but do nothing in this case) and with the UDI generated by hand. Can't get this to work
I've managed to solve the problem. For reference, when using UserPicker, the value expects an int converted to string 😄
Copy code
postAuthor.Value = loggedInUser.Id.ToString();