It seems that the fields associated with LayoutXml don't actually get passed into the result from the LookupField search.
This means that when the LayoutXml is changed, it seems to have no effect on the lookup box.
Pseudo code:
function ChangeLookupFields(dateFieldOrder)
{
var viewId = Xrm.Page.getControl("xxx_regarding").getDefaultView();
var viewDisplayName = "Filtered View";
var fetchXml = `<fetch>
<entity name='xxx_entity'>
<attribute name='xxx_lastname'/>
<attribute name='xxx_firstname'/>
<attribute name='{dateFieldOrder}'/>
<order attribute='{dateFieldOrder}' descending='false'/>
</entity>
</fetch>`.replace(/{dateFieldOrder}/g, dateFieldOrder);
var layoutXml = `<grid name='resultset' object='10005' select='1' icon='0' preview='0'>
<row name='result' id='xxx_xxxxid'>
<cell name='{dateField}' width='50'/>
<cell name='new_name' width='100'/>
</row>
</grid>`.replace(/{dateField}/g, dateFieldOrder);
Xrm.Page.getControl("xxx_regarding").addCustomView(viewId,"xxx_entity", viewDisplayName, fetchXml, layoutXml, true);
}
When the lookup field is pressed, it doesn't seem to return the same column names as what was specified. In this case when the lookup field was triggered.
Here is from the first run (no records in this one):
ChangeLookupFields("xxx_lastscheduleddate"); <--- is ran.. The lookup button is pressed..
Returned ->
"<SearchResults><items><records morerecords="0" position="0"></records></items><Layout><Entity otc="10007"><Columns><new_lastscheduleddate width="100" /></Columns></Entity></Layout></SearchResults>"
ChangeLookupFields("xxx_lastscheduleddate2"); <---- is ran... The lookup button is pressed...
Returned ->
"<SearchResults><items><records morerecords="0" position="0"></records></items><Layout><Entity otc="10007"><Columns><new_lastscheduleddate width="100" /></Columns></Entity></Layout></SearchResults>"
Unsupported pseudo fix:
It should have updated the columns field.. but doesn't seem to do it. This means that the information for xxx_lastscheduleddate2 wont be shown on the lookup. I had to go into formcontrol bundle just before these two lines...
if (webMethodName === 'RetrieveInlineSearchResults') {
this.$D4_5($v_B);
}
if (webMethodName === 'RetrieveItem') {
this.$F7_5($v_B, searchValue);
}
And write something like this:
//New pseudo code:
If (stuckColumnReturnedNotInLayoutXml())
$v_B.ReturnValue = result.replace(“stuckfield”,XUI.Xml.SelectNodes(XUI.Xml.LoadXml($v_A.layoutXml),'/grid/row/cell')[0].attributes.name.value);
*This post is locked for comments