Relation selector in a Fragment Callback


#1

I have 2 objects ‘Reminder’ and ‘Reminder Type’ related by one Reminder Type to many Reminders. I have a pop up to create a Reminder record, that has a relation selector to select the Reminder Type. I’d like to use a Fragment Callback to get values from the selected Reminder Type record to populate values in the Reminder once the type has been selected. The code below should get the text field ‘detail’ from the Reminder Type and set it to the ‘detail’ field of the Reminder:

var values = fragment_presenter.get_values();
if (!values) return;
var selection_detail = mats.ref(‘hr_reminder_detail’);
var reminder_detail = values[selection_detail];
fragment_presenter.set_value(reminder_detail);

Is the problem that the relation doesn’t yet exist (it’s only been selected on the page) - if so how do you return values through the relation selector?

Thanks,
James


#2

You are able to access the record ID of the selected relation. If this doesn’t appear to be working I would double check that your reference is correct. It needs to be a Field Path reference, to the ID of the related object.
If your current reference is only for the Relation Path, then you can either create a new one, or alternatively update your code to add ‘:id’ onto the end, like this:

var selection_detail = mats.ref(‘hr_reminder_detail’) + ‘:id’;

If you are still having issues, you can output the content of values to the Detective to ensure that the relation field is showing an ID as its value:

mats.log(values);


#3

Thanks Bob,

Your fix gives me the ID of the selected Reminder Type, but I’m trying to return another of the fields in the ‘Reminder Type’ object (i.e. the ‘Detail’ field). Do I have to add another step to perform a mats.search using the returned ID, or can I access the ‘Detail’ field directly?

James


#4

Yes you would need to do a separate mats.search to fetch any fields from about that record if you need to use it in your form. Obviously once saved you will then have a relationship to that record and can access any fields via that directly, but if you need to display something on the form before submitting then you will have to do a lookup independently.


#5

That’s worked now, thanks!