Or when you say you "want to fill product category via code", do you mean setting the property's value on the content page? If so, then as long as the property's value matches the value of the Data List item, then it should display the correct option.
(or if you don't want to Data List, that's totally cool - I just wanted to help resolve any issues you may have experienced) 🙂
I tried two approach for Contentment datalist and both not worked.
First :
I tried simple approach by creating product object and filled the category object
get all category...
IEnumerable<IContent> categorycontent= _contentService.GetPagedDescendants(1281, 0,1000,out var children);
var parentId = Guid.Parse("ce3dc5b0-9740-42e7-bcc3-f5a2647e2656");
var person = _contentService.Create("James", parentId, "productdetails");
person.SetValue("productList", categorycontent[1], "en-US");
with this approach....person object is filled but when i open the same object in Umbraco admin editor..."productList" filled category value not populate.
Second :
I try to use below mention code to get the Contentment data list but not able to get.
Not able to get datatype of dataType.Configuration.
> var dataType = _dataTypeService.GetDataType("ProductDetails - Category
> - [Contentment] Data List");
> UmbracoContentDataListSource prevalues = (UmbracoContentDataListSource)dataType.Configuration;
> //get the id of the prevalue for 'val'
> var selectednewslettervalue = prevalues.Fields.Where(a => a.Name == "seasonal").Select(a => a.Key).ToArray();
And another issue i faced with Contentment is multilingual means I published category for 2 language but in multilingual product dropdown values comes always in english(Default culture).
Also, when i use the graphql query to get ProductCategory value....it comes null...other properties values comes from query not category....because of culture issue
At this point the categorycontent[1] would typically throw an error, as you can't make an indexed call on an IEnumerable<T>. Unless it was cast as a List<T>. Anyway, it still wouldn't be want you wanted, as that would attempt to save the IContent as the property value - where as with the Contentment Data List's "Umbraco Content" data-source, the raw values are the UDI reference of the content node, not the content node itself.
You could try something like categorycontent.First().GetUdi(). (This makes an assumption there are categories and isn't a null).
...
For a fuller example, this is how you could try it...
var categories = _contentService.GetPagedChildren(1281, 0, 1, out var _);
if (categories.Any())
{
var firstCategory = categories.First();
var parentId = Guid.Parse("ce3dc5b0-9740-42e7-bcc3-f5a2647e2656");
var person = _contentService.Create("James", parentId, "productdetails");
person.SetValue("productList", firstCategory.GetUdi(), "en-US");
_contentService.Save(person);
}
...
With the multi-lingual issue, unfortunately it's not a feature that I've been able to add to Contentment Data List. I tried, but due to a combination of how Data List works and how the Umbraco backoffice lets you switch cultures, it wasn't reliable.
So with multi-lingual, your options are to either let it display in the default language, or to develop your own custom property editor (that doesn't follow the restrictions of the Data List editor).
Alternatively, have you considered using Umbraco's built-in Content Picker? As this would let you select a single value, and should support multi-lingual/culture variants.
Thanks Lee for this help. your Content Picker advise works for me...now lets see what client say...who want to consume it.
Actually I just started Umbraco and directly jumped into Umbraco 9 so I am facing lots of hurdles.
Another hurdle I am facing with Media in case Multilingual. Means I added Media Picker in document type and as Media is not Multilingual so i am not getting the Media URL in graphql. Media ID i am able to get.
Can you please help me with this...either need to customise graphql or umbraco code.
Personally, I don't know much about GraphQL, nor how it is being implemented within your web-application.
My guess would be that there should be some kind of object-mapping for the GraphQL provider that could be hooked into? Then for the Media Picker property, it'd be a case of returning the URL instead of the ID (which would be the value that Umbraco would be storing in the database).
Sorry I can't help more on your follow up question.
Your best bet is to reply on your original topic/thread so that it bumps back up to the top of the forum and hopefully someone with the knowledge can help. Good luck!
Need to Create custom datasource for Umbraco Dropdown
Hi Team,
I want to create a custom values dropdown list source via code in Umbraco.
Requirement is : Product is part of Category and I need to create dropdown for already created category and it should be multi-lingual.
I used Contentment datalist source but the issue with that, when i want to fill product category via code...it doesn't work.
Please suggest, how to create custom source dropdown list.
Thanks in advance
Hi Mahender,
I'm curious what the issue you experienced with Contentment's Data List custom data-source?
It should be possible via code, see this section of the Data List docs: https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/data-list.md#extending-with-your-own-custom-data-source
Or when you say you "want to fill product category via code", do you mean setting the property's value on the content page? If so, then as long as the property's value matches the
value
of the Data List item, then it should display the correct option.(or if you don't want to Data List, that's totally cool - I just wanted to help resolve any issues you may have experienced) 🙂
Cheers,
- Lee
Hi Lee,
I tried two approach for Contentment datalist and both not worked.
First :
I tried simple approach by creating product object and filled the category object
also used this approach to set category
with this approach....person object is filled but when i open the same object in Umbraco admin editor..."productList" filled category value not populate.
Second :
I try to use below mention code to get the Contentment data list but not able to get. Not able to get datatype of dataType.Configuration.
And another issue i faced with Contentment is multilingual means I published category for 2 language but in multilingual product dropdown values comes always in english(Default culture).
Also, when i use the graphql query to get ProductCategory value....it comes null...other properties values comes from query not category....because of culture issue
Please help me with this.
Hi Mahender,
You were close with your first code snippet.
First thing I noticed was with this line...
This will query for the first 1000 child nodes, but you only seem to need the first one, so you could reduce the query down to only get the first one.
With the
.SetValue()
call...At this point the
categorycontent[1]
would typically throw an error, as you can't make an indexed call on anIEnumerable<T>
. Unless it was cast as aList<T>
. Anyway, it still wouldn't be want you wanted, as that would attempt to save theIContent
as the property value - where as with the Contentment Data List's "Umbraco Content" data-source, the raw values are the UDI reference of the content node, not the content node itself.You could try something like
categorycontent.First().GetUdi()
. (This makes an assumption there are categories and isn't anull
)....
For a fuller example, this is how you could try it...
...
With the multi-lingual issue, unfortunately it's not a feature that I've been able to add to Contentment Data List. I tried, but due to a combination of how Data List works and how the Umbraco backoffice lets you switch cultures, it wasn't reliable.
So with multi-lingual, your options are to either let it display in the default language, or to develop your own custom property editor (that doesn't follow the restrictions of the Data List editor).
Alternatively, have you considered using Umbraco's built-in Content Picker? As this would let you select a single value, and should support multi-lingual/culture variants.
Cheers,
- Lee
Thanks Lee for this help. your Content Picker advise works for me...now lets see what client say...who want to consume it.
Actually I just started Umbraco and directly jumped into Umbraco 9 so I am facing lots of hurdles. Another hurdle I am facing with Media in case Multilingual. Means I added Media Picker in document type and as Media is not Multilingual so i am not getting the Media URL in graphql. Media ID i am able to get.
Can you please help me with this...either need to customise graphql or umbraco code.
Hi Mahender,
Is your Media Picker / GraphQL issue the one that you outline on this forum thread?
https://our.umbraco.com/forum/using-umbraco-and-getting-started/109309-graphql-custom-query-for-media-picker-url-value
Personally, I don't know much about GraphQL, nor how it is being implemented within your web-application.
My guess would be that there should be some kind of object-mapping for the GraphQL provider that could be hooked into? Then for the Media Picker property, it'd be a case of returning the URL instead of the ID (which would be the value that Umbraco would be storing in the database).
Sorry I can't help more on your follow up question.
Your best bet is to reply on your original topic/thread so that it bumps back up to the top of the forum and hopefully someone with the knowledge can help. Good luck!
Cheers,
- Lee
Thanks Lee for this help. As I am new to Umbraco, so every help is great for me.
is working on a reply...