Answered by:
retrieve case records using lookup id

Question
-
I have a field in case "lookup1". I got the id of this lookup.
Now i want to retrieve all the cases having this same lookup id. How do i do it using plugin.Thanks
Monday, December 29, 2014 7:16 AM
Answers
-
Hi,
As you have got the Id of the lookup you can use fetchXML query to retrieve your records. See below the sample code:
string fetchXml = @"<fetch distinct='false' mapping='logical'>" + "<entity name='incident'><filter type='and'>" + "<condition attribute='youlookupattributename' operator='eq' value='" + YourRetrievedValue+ "' />" + "</filter></entity></fetch>"; FetchXmlToQueryExpressionRequest fxmlReq = new FetchXmlToQueryExpressionRequest() { FetchXml = fetchXml }; FetchXmlToQueryExpressionResponse expression = (FetchXmlToQueryExpressionResponse)service.Execute(fxmlReq); var request = new RetrieveMultipleRequest { Query = expression.Query }; EntityCollection entityList = ((RetrieveMultipleResponse)service.Execute(request)).EntityCollection; for (int e = 0; e < entityList.Entities.Count; e++) { }
Check if this helps.
Thanks,
Prasad
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
- Edited by Prasad Parameswaran Monday, December 29, 2014 8:41 AM
- Proposed as answer by Guido PreiteMVP Monday, December 29, 2014 9:41 AM
- Marked as answer by HIMBAPModerator Friday, January 2, 2015 4:15 AM
Monday, December 29, 2014 8:41 AM -
And if you want to use query expression here it is
ColumnSet columSet = new ColumnSet(new string[] {"your field list"});
QueryExpression query = new QueryExpression()
{
EntityName = "incident",
ColumnSet = columSet,
Criteria =
{
Conditions = {
new ConditionExpression("Lookupfieldname",ConditionOperator.Equal,Lookupid)
},
},
};Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Proposed as answer by Guido PreiteMVP Tuesday, December 30, 2014 9:58 AM
- Marked as answer by HIMBAPModerator Friday, January 2, 2015 4:15 AM
Tuesday, December 30, 2014 7:42 AMModerator
All replies
-
Hi,
As you have got the Id of the lookup you can use fetchXML query to retrieve your records. See below the sample code:
string fetchXml = @"<fetch distinct='false' mapping='logical'>" + "<entity name='incident'><filter type='and'>" + "<condition attribute='youlookupattributename' operator='eq' value='" + YourRetrievedValue+ "' />" + "</filter></entity></fetch>"; FetchXmlToQueryExpressionRequest fxmlReq = new FetchXmlToQueryExpressionRequest() { FetchXml = fetchXml }; FetchXmlToQueryExpressionResponse expression = (FetchXmlToQueryExpressionResponse)service.Execute(fxmlReq); var request = new RetrieveMultipleRequest { Query = expression.Query }; EntityCollection entityList = ((RetrieveMultipleResponse)service.Execute(request)).EntityCollection; for (int e = 0; e < entityList.Entities.Count; e++) { }
Check if this helps.
Thanks,
Prasad
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
- Edited by Prasad Parameswaran Monday, December 29, 2014 8:41 AM
- Proposed as answer by Guido PreiteMVP Monday, December 29, 2014 9:41 AM
- Marked as answer by HIMBAPModerator Friday, January 2, 2015 4:15 AM
Monday, December 29, 2014 8:41 AM -
And if you want to use query expression here it is
ColumnSet columSet = new ColumnSet(new string[] {"your field list"});
QueryExpression query = new QueryExpression()
{
EntityName = "incident",
ColumnSet = columSet,
Criteria =
{
Conditions = {
new ConditionExpression("Lookupfieldname",ConditionOperator.Equal,Lookupid)
},
},
};Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Proposed as answer by Guido PreiteMVP Tuesday, December 30, 2014 9:58 AM
- Marked as answer by HIMBAPModerator Friday, January 2, 2015 4:15 AM
Tuesday, December 30, 2014 7:42 AMModerator