Answered by:
Entity Name specified in FetchXml does not match the entity name in the EntityExpression

Question
-
Hi all, please help me,
I have a field lookup A, When i CLick on this lookup, an lookup dialog displayed.
On this dialog, i have a field "Object", that have 2 value: contact & account
Under field Object is the "View" field, all views in this field is corresponding with the selected value in Object field.
And when you choose a field some account/contact is display in grid view below
It's advanced find view in CRM.
I write a fetch XML
var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='account'>" +
"<attribute name='accountnumber' />" +
"<attribute name='name' />" +
"<attribute name='accountid' />" +
"<order attribute='name' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='grpe_statuscode' operator='eq' value='10' />" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var layoutXML = "<grid name='resultset' object='1' jump='name' select='1' preview='1' icon='1'>" +
"<row name='result' id='accountid'>" +
"<cell name='name' width='200' />" +
"<cell name='accountnumber' width='100' />" +
"</row>" +
"</grid>";to add custome view in "View" field with Object field is account
It's is ok
But when i change account to contact in Object field, an error occur :"Entity Name specified in FetchXml does not match the entity name in the EntityExpression"
What can i do now!!!!!!!!!!!!!!
Saturday, June 30, 2012 2:28 AM
Answers
-
Sorry for being ignorant but you can add custom view in the lookup dialog without writing code (out of box) then why are you writing code on the onchange of lookup object. May be I am still not clear about your question
-Devashish
http://thecrmworld.wordpress.com
http://ebizartisans.com- Marked as answer by AnyMi Wednesday, August 8, 2012 4:00 AM
Saturday, June 30, 2012 4:43 AM -
Hi ..
You are Trying to create a Custom View (or) Dynamic View .
By using Filter Look Up
Your Code Is for Account Entity Advance Find View .
If you Want For Contact Entity , You Have to Choose For Contact Entity Advance Find View..
Eg:
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name='contact'>" + "<attribute name='firstname' />" + "<attribute name='lastname' />" + "<attribute name='contactid' />" + "<order attribute='lastname' descending='false' />" + "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='eq' value='" + accountid + "' />" + "<condition attribute='statecode' operator='eq' value='0' />" + "</filter>" + "</entity>" + "</fetch>"; // build Grid Layout var layoutXml = "<grid name='resultset' " + "object='1' " + "jump='contactid' " + "select='1' " + "icon='1' " + "preview='1'>" + "<row name='result' " + "id='contactid'>" + "<cell name='firstname' " + "width='200' />" + "<cell name='lastname' " + "width='250' />" + "<cell name='parentcustomerid' " + "width='250' />" + "</row>" + "</grid>";
NOTE.. Here I have Mentioned For Contact Entity According To Your Requirement..
Refer the Bellow Link...
http://crmconsultancy.wordpress.com/2011/05/17/filtered-lookups-in-crm-2011/
You can Have a Solution For this (Refer Bellow Link..)
https://skydrive.live.com/embedicon.aspx/.Public/PointOfContact_0_0_1_0.zip?cid=0f98a78f1c3c4457&sc=documents
- Marked as answer by AnyMi Wednesday, August 8, 2012 4:00 AM
Saturday, June 30, 2012 4:50 AM -
Hi LuuHa,
Have you tried putting a debugger to the your code. As it seems to me that when contact is being selected the custom "account view" that you have created is also being added somehow (or never gets removed after being added to the lookup dialog) . As the fetch XML for account cannot be executed on contact you are getting this error.
Please put a debugger statement when you are adding custom view in the for loop and let us know how it goes.
Susan
- Marked as answer by AnyMi Wednesday, August 8, 2012 4:01 AM
Saturday, June 30, 2012 9:58 AM
All replies
-
i call this SDK.ChangeLookupView.processLookup(lookupControl, viewId, entityName, viewDisplayName, fetchXML, layoutXML);
if (typeof (SDK) == "undefined")
{ SDK = {}; }
SDK.ChangeLookupView = {
processLookup: function (lookupControl, viewId, entityName, viewDisplayName, fetchXml, layoutXml) {
debugger;
// Get the default view of the lookup before it is modified
var currentDefaultViewId = lookupControl.getDefaultView();
var oReq = SDK.ChangeLookupView.getXMLHttpRequest();
if (oReq != null) {
var url = Xrm.Page.context.getServerUrl() +
"/XRMServices/2011/OrganizationData.svc/SavedQuerySet(guid'" + currentDefaultViewId + "')";
oReq.url = url;
oReq.open("GET", url, true);
oReq.onreadystatechange = function () {
SDK.ChangeLookupView.changeLookupDefaultView(oReq, lookupControl, viewId, entityName, viewDisplayName, fetchXml, layoutXml);
};
oReq.send();
}
},
/* Override the addExistingFromSubGridAssociated function */
isLookup: function (control, index) {
return control.getControlType() == "lookup";
},
getXMLHttpRequest: function () {
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest;
}
else {
try
{ return new ActiveXObject("MSXML2.XMLHTTP.3.0"); }
catch (ex) {
return null;
}
}
},
/* Change lookup Default View */
changeLookupDefaultView: function (oReq, lookupControl, viewId, entityName, viewDisplayName, fetchXml, layoutXml) {
if (oReq.readyState == 4 /* complete */) {
if (oReq.status == 200) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(oReq.responseText);
var returnedTypeCodeNode = xmlDoc.selectSingleNode("//d:ReturnedTypeCode");
if (returnedTypeCodeNode) {
var entityName = returnedTypeCodeNode.text;
if (entityName == "account") {
lookupControl.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, false);
// lookupControl.setDefaultView(viewId);
}
}
}
}
}
};Saturday, June 30, 2012 2:43 AM -
Hi,
If I have understood your problem correctly then you will need to make two seperate Fetch XML and view XML one for contact and other for Account. Based on what has been selected by the user/operator (he can select account or contact in the lookup) you will have to use the appropriate Fetch XML. (In the on change you can examine the lookup logical name to run the appropriate Fetch XML)
Hope this helps
-Devashish
http://thecrmworld.wordpress.com
http://ebizartisans.comSaturday, June 30, 2012 3:02 AM -
But i just want to add a new custome view to filter account, and display it in grid view (result of searching)
With contact and account we already have some views correspond with them, each view is a filter condition to search account/contact.
I don't want co create a new custom view for contact, it already has it's default view
....
My problem is:
example in Object field, i choose account-> the "view" field load 3 view in combobox A , B, C ( C is my custom view). -> i choose view A -> grid view load some account. -> i go to Object field and choose contact -> the "view" field load 2 view D, F (D is default view and selected is default) -> some contact load in gridview.
Repeat all step above, except that i choose C instead of A, -> grid view load some account. -> i go to Object field and choose contact ->and a error display "Entity Name specified in FetchXml does not match the entity name in the EntityExpression"
A,B, D,F is sytem view, and just C is my custom view with the code i write before
- Edited by AnyMi Saturday, June 30, 2012 3:32 AM
Saturday, June 30, 2012 3:30 AM -
Sorry for being ignorant but you can add custom view in the lookup dialog without writing code (out of box) then why are you writing code on the onchange of lookup object. May be I am still not clear about your question
-Devashish
http://thecrmworld.wordpress.com
http://ebizartisans.com- Marked as answer by AnyMi Wednesday, August 8, 2012 4:00 AM
Saturday, June 30, 2012 4:43 AM -
Hi ..
You are Trying to create a Custom View (or) Dynamic View .
By using Filter Look Up
Your Code Is for Account Entity Advance Find View .
If you Want For Contact Entity , You Have to Choose For Contact Entity Advance Find View..
Eg:
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name='contact'>" + "<attribute name='firstname' />" + "<attribute name='lastname' />" + "<attribute name='contactid' />" + "<order attribute='lastname' descending='false' />" + "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='eq' value='" + accountid + "' />" + "<condition attribute='statecode' operator='eq' value='0' />" + "</filter>" + "</entity>" + "</fetch>"; // build Grid Layout var layoutXml = "<grid name='resultset' " + "object='1' " + "jump='contactid' " + "select='1' " + "icon='1' " + "preview='1'>" + "<row name='result' " + "id='contactid'>" + "<cell name='firstname' " + "width='200' />" + "<cell name='lastname' " + "width='250' />" + "<cell name='parentcustomerid' " + "width='250' />" + "</row>" + "</grid>";
NOTE.. Here I have Mentioned For Contact Entity According To Your Requirement..
Refer the Bellow Link...
http://crmconsultancy.wordpress.com/2011/05/17/filtered-lookups-in-crm-2011/
You can Have a Solution For this (Refer Bellow Link..)
https://skydrive.live.com/embedicon.aspx/.Public/PointOfContact_0_0_1_0.zip?cid=0f98a78f1c3c4457&sc=documents
- Marked as answer by AnyMi Wednesday, August 8, 2012 4:00 AM
Saturday, June 30, 2012 4:50 AM -
Yes, the view is like that, but this lookup view being used in many situation.
I have a form X, on form X i have a lookup field contact Y, when i click on Y, lookup dialog above will be display, and the user just only select "Acount ative &.....", so i have create new custom view for only account on" Look for" field.
Saturday, June 30, 2012 5:44 AM -
hi Parthiban.T ,
You can see my question above,
But i just want to add a new custome view to filter account, and display it in grid view (result of searching)
With contact and account we already have some views correspond with them, each view is a filter condition to search account/contact.
I don't want co create a new custom view for contact, it already has it's default view
....
My problem is:
example in Object field, i choose account-> the "view" field load 3 view in combobox A , B, C ( C is my custom view). -> i choose view A -> grid view load some account. -> i go to Object field and choose contact -> the "view" field load 2 view D, F (D is default view and selected is default) -> some contact load in gridview.
Repeat all step above, except that i choose C instead of A, -> grid view load some account. -> i go to Object field and choose contact ->and a error display "Entity Name specified in FetchXml does not match the entity name in the EntityExpression"
A,B, D,F is sytem view, and just C is my custom view with the code i write before.
I don't know why this error happen and how i fix it :(
Pa
Saturday, June 30, 2012 5:47 AM -
Hi
i have read through your situation, You can create a new Custom View and itz Displaying Itz Name , But While Selecting It Show Error
"Entity Name specified in FetchXml does not match the entity name in the EntityExpression".
This Error Due To While assigning your FETCH XML and while Assigning to Your Custom View.
Step 1:First Select Your Entity and Create a Advance Find Search and initialize Your Condition According to your. And Check weather It Get Filter and data are in it.
Step 2 : Download that Fetch XMl and Modify your Code According to That XMl Code (wich I have Mentioned Bellow) [ Here Check Schema Name and Attribute name According to your Download that Fetch XMl.
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name='contact'>" + "<attribute name='firstname' />" + "<attribute name='lastname' />" + "<attribute name='contactid' />" + "<order attribute='lastname' descending='false' />" + "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='eq' value='" + accountid + "' />" + "<condition attribute='statecode' operator='eq' value='0' />" + "</filter>" + "</entity>" + "</fetch>";
Step 3 : Now We Create a Dynamic View For the Created Fetch XML Code Above .
While Assigning Check sehema name and assign it By Bellow , Thus the Selected Column will get filtered and show in your look up.
var layoutXml = "<grid name='resultset' " + "object='1' " + "jump='contactid' " + "select='1' " + "icon='1' " + "preview='1'>" + "<row name='result' " + "id='contactid'>" + "<cell name='firstname' " + "width='200' />" + "<cell name='lastname' " + "width='250' />" + "<cell name='parentcustomerid' " + "width='250' />" + "</row>" + "</grid>";
the Above error you have mentioned is due to assign schema name , initialize your schema name , Assign it Properly Then It Work perfect..
Refer Bellow Link
http://gtcrm.wordpress.com/2011/03/22/filtered-lookup-approaches-in-crm-2011/
http://crmconsultancy.wordpress.com/2011/05/17/filtered-lookups-in-crm-2011/
CUSTOM Solution For this (For REFERENCE .. ) [ Import this solution and change your Fetch Xml schema name and your look up Schema Name)
- Edited by Parthiban.T Saturday, June 30, 2012 6:53 AM
Saturday, June 30, 2012 6:41 AM -
Saturday, June 30, 2012 7:57 AM
-
hi Parthiban.T ,
i done similar,
i have create new view, and filter data ok for account
but when i change "Look for" value from account to contact, error happen
This error no happen while : i choose system view of account -> change "Look for" value from account to contact, the system views of contact is fill in ther dropdown list
Saturday, June 30, 2012 8:30 AM -
Hi ..
Within a lookup you need to create 2 Dynamic View (Account & Contact) .
We cant Create such view According to it.
Either We can create an another function for filter lookup for Contact Entity and place another Look up and we can view it.
or
create a filter criteria for Contact Entity and Place it under a condition state and try to call that function eg : If()
or
Create a View and Make according to your condition and place it System View Instead of Dynamic View .
------------------------------------------------------------------------------------------------------------------------------------------
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Saturday, June 30, 2012 9:24 AM -
Hi LuuHa,
Have you tried putting a debugger to the your code. As it seems to me that when contact is being selected the custom "account view" that you have created is also being added somehow (or never gets removed after being added to the lookup dialog) . As the fetch XML for account cannot be executed on contact you are getting this error.
Please put a debugger statement when you are adding custom view in the for loop and let us know how it goes.
Susan
- Marked as answer by AnyMi Wednesday, August 8, 2012 4:01 AM
Saturday, June 30, 2012 9:58 AM -
To summarize my problem:
_ I have 2 entities: account and contact
_ On contact's form: I have a lookup to account entity
_ My business: when the user clicks the account lookup, the popup filters ACTIVE accounts only (set to "Active accounts" view).
_ Codes to do that :
... (like i post before)
- It's OK but on the "Look for" popup, if I SELECT another entity (ex: contact) from the entity list, I got this error:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Xml.XmlException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #23A3F27EDetail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>System.Xml.XmlException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #23A3F27E</Message>
<Timestamp>2012-07-02T03:34:46.0126953Z</Timestamp>
<InnerFault>
<ErrorCode>-2147217112</ErrorCode>
<ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Entity Name specified in FetchXml does not match the entity name in the EntityExpression</Message>
<Timestamp>2012-07-02T03:34:46.0126953Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</InnerFault>
<TraceText i:nil="true" />
</OrganizationServiceFault>Monday, July 2, 2012 4:07 AM -
Hey.
For the reason why 'we' want to use this way to change default type is because it is supported by SDK.
I have exactly the same issue. A bit further investigation shows something interesting.
Scenario:
I have added a custom view for phonecall actvity in the 'to' field.
Xrm.Page.getControl("to").addCustomView(viewId, entityName, viewName, fetchXml, layoutXml, true);
Everything works perfectly as expected. When i open the lookup field, the default type is contact and the view is defaulted to my custom view.
The error will pop up when now you just change the type of the entity by clicking 'look for' field in the lookup dialog. However,
if you select another system view in the contact view list and click 'look for', the error is GONE.
A very interesting behaviour from my point. A bug maybe.
If anyone has a solution for this, it would be great.
Jaimie
Wednesday, August 8, 2012 2:10 PM -
This has been confirmed as a bug and shall be released as a fix in the future rollups
Symptoms
====================================
The addCustomView SDK sample will fail on a multi-entity lookup (Example: Parent Customer lookup on the Contact form) when you switch from the custom generated view to one of the other entity types.
Workaround
====================================
There is a workaround, but it should not be required. Once the lookup loads, the view will be the custom generated view. You must first change the selected view to one of the available system views, and then change the entity type. If you first change the entity type without changing to a system view, the form will throw an exception.
Customer Impact
====================================
The customer has to go through the extra steps of changing the selected view to a system view before changing the entity type. This is problematic as this customization can be on a number of different forms, and it would require each user to be educated on what views they have to complete the workaround on. This type of customization should be seamless to the end user.Steps to recreate:
============
1. Copy the sample jscript from http://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_addCustomView
2. In CRM create a new Jscript Web Resource with code from step 1. (Settings, Customizations, Customize The System, Web Resources and New)
3. Add the web resource to the Contact entity form. (Settings, Customizations, Customize The System, Expand Entities, Expand Contact, Open main form, click form properties and Add Form Libraries)
4. Add function SDK.ControlSamples.addCustomView as an Onload event (The SDK Sample defines the SDK.ControlSamples namespace, so you must utilize it when adding the function to the onload event.). In the same customizations location as step 3 click Add in the Event Handlers Section, choose the library created in step two and the function SDK.ControlSamples.addCustomView.
5. Save and Publish All customizations
6. Open an existing Contact record, or create a new Contact record.7. Select the magnifying glass to load the lookup form for the Parent Customer field. The custom view "SDK Sample View" should be loaded for the Account entity.
8. Change the Look for: dropdown to Contact, and you will receive the error below.
====================================
Actual Result
====================================
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Entity Name specified in FetchXml does not match the entity name in the EntityExpressionDetail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147217112</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>Entity Name specified in FetchXml does not match the entity name in the EntityExpression</Message>
<Timestamp>2012-05-04T21:06:30.0220608Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</OrganizationServiceFault>====================================
Expected Result
====================================
The view should switch gracefully and display to default view of the selected entity type.- Proposed as answer by Jaimie_J Thursday, August 9, 2012 2:01 PM
Thursday, August 9, 2012 2:01 PM -
hi Jaimie_J
It seem we can not fix this error at the moment
But in another way, after you add custom view -> you can disable "Look for" and "View" dropdown
http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/7eb190bc-30d1-473e-905f-73f5e11aa547
Friday, August 10, 2012 7:24 AM -
Hi Jaimie,
I opened a microosft case for this exact issue. They closed it on me without any warning... did they confirm that this was a bug and when it will be addressed?
In my situation, i simply need to swich the object type to users after the custom view was added to contact. Heres what i did to fix it:
Note: this is an UNSUPPORTED customization/workaround
1. change the lookupinfo.aspx file located on the crmwebsite:
C:\Program Files\Microsoft Dynamics CRM\CRMWeb\_controls\lookup
2. modify the function: OnRecordTypeChange
function OnRecordTypeChange(oSelect, bFromOnLoad)
{
if (bFromOnLoad)
{
var findCriteria = document.getElementById("crmGrid_findCriteria");
if (!IsNull(findCriteria) && findCriteria.value != "")
{
isSearchOn = true;
}
}
if (typeof(showMyRecordsSpan) == "object")
{
if (_showMyRecordsFilter[oSelect.value])
{
showMyRecordsSpan.style.display = "inline";
}
else
{
showMyRecordsSpan.style.display = "none";
}//This is a crm bug when switching objects from a custom fetch xml view of a different object type.
// Contact has custom fetchxml > switching to user will throw error unless we set the default user viewif (oSelect.value == 8) //user
{crmGrid.SetParameter("viewid", "{00000000-0000-0000-00AA-000010001004}"); //point to any view in system
crmGrid.SetParameter("fetchXml", "");
crmGrid.SetParameter("layoutXml", "");
crmGrid.Reset();}
- Proposed as answer by CRM Smith Tuesday, September 11, 2012 3:57 PM
Tuesday, September 11, 2012 3:55 PM -
the above breaks the assign lookup, adding one more condition fixes the issue:
if (oSelect.value == 8) //user
{if (crmGrid.GetParameter("viewid") == "{00000000-0000-0000-0000-000000000000}")
{crmGrid.SetParameter("viewid", "{00000000-0000-0000-00AA-000010001004}"); //point to any view in system
crmGrid.SetParameter("fetchXml", "");
crmGrid.SetParameter("layoutXml", "");
crmGrid.Reset();}
}
Thursday, September 13, 2012 1:33 PM -
Hi.
CRM 2011 rollup 10 included the fix for this problem.
http://www.microsoft.com/en-us/download/details.aspx?id=30711
- Views that are added to a lookup dialog box by using the addCustomView function from the Microsoft Dynamics CRM 2011 Software Development Kit (SDK) do not use default sorting. However, the default sorting that was defined as part of the FetchXml schema that was passed to the function should be used.
- The AddCustomView method from SDK does not work on a multi-entity lookup as expected.
Jaimie
- Proposed as answer by Jaimie_J Thursday, September 13, 2012 1:49 PM
Thursday, September 13, 2012 1:49 PM -
Hi Jaimie,
Is this working for you? I installed UR 10 and I expected it to be fixed, but the issue still remained... Any thoughts?
Ryan
Tuesday, November 20, 2012 4:54 PM