How to programmatically sort a pointer field on a product/variant?

I’m looking to solve a problem where we need to sort our documents that we link to a product using a pointer. The pointer is of the type MediaFile and has MultiSelect set as true.

From what I can see when looking at the values in the database, is there a index for each pointer added to this field. And it is possible to sort the field using the UI. But I cant find any good way to set this index from code.

So I would like to know if anyone have any tip or solution on how to sort this field programmatically?

Litium version: 7.7.1

You could sort the list according to your criteria before updating the field on the product, passing the sorted list as the value.


var values = product.Fields.GetValue<IList<PointerItem>>(Constants.FilePointerField).Select(x => x.EntitySystemId.MapTo<File>());

values = values.OrderBy(x => x.Name);

product.Fields.AddOrUpdateValue(Constants.FilePointerField, values);


Seems reasonable enough to me, not sure why I did not think of that from the start.
Will give it a try!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.