mats.Search for a Composite

I have created a Widget that displays one property of an object. If I select a text property it works just fine, however I want to display a composite. In this case the mats.Search returns a long hexadecimal string - which if I decode it looks like the references to the individual fields in the composite. How do I get the text value of the composite in the same way as I do a text property? My code is:

var selects = {};
selects.somefield1 = field1;
var result = mats.search({
‘record_id’: id,
‘selects’: selects,
‘return’: ‘value’
});
mats.log ("Result is " + JSON.stringify(result));

id is the recordid which is presumably correct as it works for a text field.
field1 is a reference to the field, which also works for the text field.

Thanks

Hey Richard

For v10.2: If you simplify a little and use the record object instead:

var selects = {};
selects.somefield1 = field1
var result = mats.record(id)

then you can use the second argument of record.get():

var data = result.get(selects, 'displayable');

Otherwise (and compatible with versions prior to 10.2) you can use:

var disp_value = mats.displayable('field_path_reference', value)
1 Like

Thanks Mark, worked perfectly.

One comment for anyone revisiting this - “data” in Mark’s response will be an object and the value needed is in the somefield1 property. I used:

var data = result.get(selects, ‘displayable’).somefield1;

In my case the field was also multi-line, formatted so I had to do a global replace of &lt; to < and &gt; to > too (as I wanted the html)

To add to that - if ‘selects’ in your example is a single field (and not an object) then the return value will be just the resolved value, too. Cleaner, depending on your specific circumstances. So using your full example:

var select = mats.ref('my_field');
      // ^ will be a string this time, not an object

var result = mats.record(id)

var displayable_field_value = result.get(select, 'displayable');
      // ^ gives you just a single, usable value

Mark

1 Like

Gets better and better!