You need to define a method to initialise a value if one can be found.
You may want to override the render/rerender
object and call your method there or you could try attaching it to an attribute change handler - or finally, you could expose the initData routine via an aura:method
and call it manually.
Your class would be something like this (note this is untested and can't really be tested as you have not provided all the required code - for example, you have not define what your Apex controller search method looks like):
initData: function(cmp) {
var action = cmp.get('c.getCurrentValue');
var self = this;
action.setParams({
'type': cmp.get('v.ObjectString'),
'value': cmp.get('v.recordId'),
// you don't seem to have a record id attribute,
//so you will need to add it and store it when you find a record
});
action.setCallback(this, function(a) {
if (a.error && a.error.length) {
return $A.error('Unexpected error: ' + a.error[0].message);
}
var result = a.getReturnValue();
cmp.set("v.SearchKeyWord", result);
if (null != result) {
// Show the Lookup pill
var lookupPill = cmp.find("lookup-pill");
$A.util.removeClass(lookupPill, 'slds-hide');
// Lookup Div has selection
var inputElement = cmp.find('searchRes');
$A.util.addClass(inputElement, 'slds-has-selection');
}
});
$A.enqueueAction(action);
}
You can display only one additional field in Search Results. As per your screenshot, you have Account Name and you cannot have more than one field along with Name.
To customize: Go to Search layout of Parent Object (Opportunity) > Search Results > Edit > Add your field next to Name.
If you have multiple fields in Search Results, It takes first two acceptable data type fields in lookup results. (In your case, Opportunity Name and Account Name)
In this case, I have a Close Date in Search Results, So it will display on every Opportunity Lookups.
Please note, all type of fields are not supported in search results. For example, you cannot add picklist type fields in Search Results. Even if you try to add, it skips such kind of fields and display next availale field which is acceptable (Text, Date, Number & etc). ** I do not have acceptable types.
If the field that you want to see in lookup results is not acceptable, You can create a formula field and add it in 2nd position (Workaround). This way you can show that field in lookup results.
Also, if you want to display multiple fields (as per your question) you can separate them with comma (,) and add it in Search Results. - Workaround.
Your search also perform on second field. So please be careful
Hope it helps.
Best Answer
OwnerId
is not supported inlightning:inputField
. Refer to the excerpt below from documentation: