1

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
  • 1
    Are the pre-populated items always the same? If so, you can specify them in the standard values. If not, you will likely need to implement an item:created event handler to dynamically add the items you want. Commented Mar 6, 2019 at 13:45

1 Answer 1

3

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:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.