But why is this all necessary, there is no documentation about this (as far as I can tell) and the previous way of doing it (with an integer Id) seems much more straightforward to me!?
I think there are not so many documentation because it's pretty new feature. And Guys from HQ haven't enough time for upgrading all stuff. Maybe we can contribute to documentation section ) Nice idea.
I tried Alex's approach in 7.7.6, and it half works; it does save successfully, when I go to the edit page I see the correct related document, but when I try loading the published page I get some errors in my template accessing the related document's properties.
In terms of the OP's original example, this
CurrentPage.ProductPicker.Name
would fail with error 'Umbraco.Core.GuidUdi' does not contain a definition for 'Name', and this
Model.Content.ProductPicker.Name
Would fail with error Object reference not set to an instance of an object, ProductPicker being null.
Any idea why?
[EDIT]
I think I figured it out. The related document was also created via the ContentService, and when I check its properties, the "Link to document" says "This document is published but is not in the cache". After I click "Save and publish", I get an actual link to document and after I click "preview" the original problem I had is fixed. This is not ideal, as I have 300+ more documents I will create via the ContentService, but at least I can move on.
If like myself you only ever use Multi Node Tree Pickers, instead of the actual real Content Picker, because of their superior capabilities then you need to set the value to a string.
If you really are using the old Content Picker data type, then yeah memory serves me right, it does take an int. So I'm not sure what the issue is - presuming the alias of the property field really is 'productPicker' etc.
Unable to set value of content picker
Hey all,
I'm having this little issue. I don't seem to be able to set the value of a content picker data type.
I have 2 Document Types:
Product
Ordered Product
Ordered Product has a property "Product Picker" (new data type based on content picker).
I need to set the value programmatically, but I don't seem to be able to get that to work :'(
My code: (cntsvc is my ContentService)
What am I doing wrong? Do I need to set some other value other than the Id ?
Thank you.
K.
Hi
What version of Umbraco are you using? If it's 7.6 you have to use UID instead of ID.
Thanks,
Alex
Version = 7.6.1
How do I get the UID? IPublishedContent doesn't seem to have such a property...
Thanks
Error:
That worked :) Thank you!
But why is this all necessary, there is no documentation about this (as far as I can tell) and the previous way of doing it (with an integer Id) seems much more straightforward to me!?
Anyway, thanks again!
You are welcome! Glad to help.
I think there are not so many documentation because it's pretty new feature. And Guys from HQ haven't enough time for upgrading all stuff. Maybe we can contribute to documentation section ) Nice idea.
Alex
I tried Alex's approach in 7.7.6, and it half works; it does save successfully, when I go to the edit page I see the correct related document, but when I try loading the published page I get some errors in my template accessing the related document's properties.
In terms of the OP's original example, this
would fail with error 'Umbraco.Core.GuidUdi' does not contain a definition for 'Name', and this
Would fail with error Object reference not set to an instance of an object, ProductPicker being null.
Any idea why?
[EDIT]
I think I figured it out. The related document was also created via the ContentService, and when I check its properties, the "Link to document" says "This document is published but is not in the cache". After I click "Save and publish", I get an actual link to document and after I click "preview" the original problem I had is fixed. This is not ideal, as I have 300+ more documents I will create via the ContentService, but at least I can move on.
Hi K,
If like myself you only ever use Multi Node Tree Pickers, instead of the actual real Content Picker, because of their superior capabilities then you need to set the value to a string.
If you really are using the old Content Picker data type, then yeah memory serves me right, it does take an int. So I'm not sure what the issue is - presuming the alias of the property field really is 'productPicker' etc.
Cheers
Jonathan
I am using a Content Picker data type, not a Multinode Treepicker.
is working on a reply...