web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Lookup field columns not changing with LayoutXml or FetchXml

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    Wrote something even better. Basically looks at the Layout XML and includes these fields into the Result Columns (like it should). Note it only looks at the name and width fields. 

    		if (!IsNull($v_A) && $v_A.layoutXml != null) {		
    			debugger;
    
    			  layoutCellNodes = XUI.Xml.SelectNodes(XUI.Xml.LoadXml($v_A.layoutXml),'/grid/row/cell');
    			  var columnText = "";
    			  for (var i = 0; i < layoutCellNodes.length; i++) { 
    				columnText += '<' + layoutCellNodes[i].attributes.name.value + ' width="' + layoutCellNodes[i].attributes.width.value + '"/>';				  //todo maybe more than just the value and width.  
    			  }
    
    			ReturnXml = XUI.Xml.LoadXml($v_B.ReturnValue);
    			XUI.Xml.SelectSingleNode(ReturnXml,'/SearchResults/Layout/Entity/Columns').innerHTML = columnText;
    			$v_B.ReturnValue = ReturnXml.children[0].outerHTML;
    		}


    It basically takes in this code:

        var fetchXml = `<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                        <entity name='appointment' >
                            <attribute name='scheduledstart'/>
                            <attribute name='scheduledend'/>
                            <attribute name='statecode'/>
                            <filter type='and'>
                                <condition attribute='regardingobjectid' operator='eq' value='{eventID}'/>
                            </filter>
                           </entity>
                           </fetch>`.replace(/{eventID}/g, eventID);
    
        //Figure out the object id for the appointment
        var layoutXml = `<grid name='resultset' object='4201' select='1' icon='0' preview='0'>
            <row name='result' id='activityid'>
                <cell name='scheduledstart' width='100'/>
                <cell name='statecode' width ='50'/>
                <cell name='subject' width='50'/>
            </row>
        </grid>`;

    And makes sure that in the result all the fields are shown in the lookup as it should:

    3566.Lookup.png

    Without this fix, it would use the columns scheduledend and statecode (which isn't what my LayoutXML asked for, plus in my case the scheduledend is empty for all data), this can be seen on version 8.1.0001.1005. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans