Sorting asset list by sum of 2 metadata field values


(Klye) #1

Matrix Version: 5.4.2

I need to sort an asset listing by the total of two metadata values. They’re accommodation contract options, and each asset has a metadata value for room rate and another for meal package rate (text fields). Originally, the total only needed to be printed on the front end, so I’ve use the following keyword replacement in the type format to display the total on the front end: %asset_metadata_Room_rate^add:{asset_metadata_Meal_rate^number_format:2%

I now have an additional requirement to sort a listing by this total, but the total doesn’t actually exist as an asset attribute. I’ve added a “total” metadata field and attempted to automatically populate this with the keyword replacements in a few different formats as the default value, but that doesn’t seem to work. Is there an easy way to do this, without my having to manually populate this new field with the calculated value?


(Kequi) #2

Hi,

I’ve not done this before myself - but have you tried sorting by “asset keyword value” - then dropping your keyword in there?

You’d have to remember to have the default sorting set to “presentation value” and not RAW.

Not sure what the performance hit would be for doing it that way.

What default keywords have you tried?

The other option is to use triggers to set the total metadata value when the other fields are updated (you’d need to replace keywords and ‘fix’ the value so it’s not in keyword format in the metadata.)

Karl


(Peter McLeod) #3

Hi

you could try using a new metadata field that has a default value of the 2 added metadata values using a keyword replacement such as:

%metadata_field_num1^add:{asset_metadata_num2}%

set this as the default metadata value, replacing num1, num2 with your metadata field names. Then the sort to be based on this metadata field.

Thanks
Peter


(Klye) #4

Thanks @PeterM - I did try that, but it’s not calculating. The third field only picks up the first value, and doesn’t add the second. I have found a workaround, though, by cascading, as the second value is quite uniform.


(Klye) #5

Thanks @karleq - I tried that, but may have gotten the format wrong. I have found a reasonable workaround though.