locked
retrieve case records using lookup id RRS feed

  • 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.



    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.

    Tuesday, December 30, 2014 7:42 AM
    Moderator

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.



    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.

    Tuesday, December 30, 2014 7:42 AM
    Moderator