Is there a way to use sitecore query on multilist field where it can pre populate the items on right hand side ? I need to pre populate items from a particular template in descending order based on a field and limit as 10. By default the selection will be pre populated and later user can select anyother item and rearrange it.
1 Answer
If you have complex logic to fill the Multilist with items you can use code data source like we are doing it in e.g. Rendering Variants:
public class MyCodeDatasource : IDataSource
{
public Item[] ListQuery(Item item)
{
string url = ServiceLocator.ServiceProvider.GetService<IContext>().RawUrl;
if (url.Contains("hdl"))
{
//if you need context item you can access session object using hdl and get the item ID from there
}
//put your logic to get items here and rearrange them as you want
return Array.Empty<Item>();
}
}
You can use this like this:
item:created
event handler to dynamically add the items you want.