Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a document type that has Member Picker property editor and I need to set the value for it programmatically. Member that I need to put into that property is a custom Member Type. When I try to do it in the back office, it works, but I can't get it to work through an API. I've tried few things and it successfully creates node of that document type, but when I access that node through backoffice I always get this exception:
System.InvalidOperationException: Multiple actions were found that match the request: GetByIds on type Umbraco.Web.Editors.EntityController GetByIds on type Umbraco.Web.Editors.EntityController GetByIds on type Umbraco.Web.Editors.EntityController
Also, Member Picker doesn't show anything in node editor (as if it has no selected member).
Thanks in advance!
What does your call to SetValue look like? That exception generally means that the saved value isn't in the format that the picker expected.
The multiple actions that the exception refers to accept IDs in different formats. If the provided value doesn't match any of those formats then it tries to pick one of the actions to call with an empty list of IDs, but has no way to decide.
Hi Steve, thanks for your reply!
Here's how my call of Set value looks:
And here's how my Get and Set methods look:
public static int GetMemberIdProperty(IPublishedContent node, string memberProperty)
int id = 0;
var doctor = node.Value<IPublishedContent>(memberProperty);
id = doctor.Id;
public static IPublishedContent SetMemberIdProperty(PrescriptionViewModel prescription)
IPublishedContent doctor = ContentHelper.umbracoHelper.Member(prescription.DoctorId);
As I mentioned, Set method successfully creates new node, but when Get method is called, it throws this exception:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
On this line:
id = doctor.Id;
Also, when I debugged those two methods, I've seen that doctor variable gets null value.
One more thing. In documentation it says that Member Picker returns IPublishedContent, so I've tried to set it to that same type, but it doesn't work.
PS PrescrtiptionViewModel is a view model for document type Prescription that has Member Picker property (I use it for CRUD methods to work with JSON that I recieve through a HTTP request).
I GOT IT!
I've had similar problem with setting value for media picker and thought I could try doing the same thing AND IT WORKED!
Here's how I did it:
public static IMember SetMemberIdProperty(int memberId, ServiceContext service)
And then in the call:
content.SetValue("prescriptionDoctorId", MemberHelper.SetMemberIdProperty(prescription.DoctorId, service).GetUdi());
Seems like you need Udi for setting values of all picker data types.
Hope it helps someone some day too!
That makes sense, the pickers do store UDIs. When you pass the Member to SetValue, it ends up calling ToString() and storing the result in the database. But calling ToString() just returns "Umbraco.Core.Models.Member".
Passing in a Member, Content or Media to set a picker seems a perfectly reasonable thing to do, though. It would be good to get SetValue to handle that and store the UDI for you, and similarly handle passing in an IEnumerable<Media> for multiple pickers.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted