Friday 13 April 2012

Get Opportunity Task Information using FetechXML

private EntityCollection GetOpportunityTaskCollections(IOrganizationService service, Guid _opportunityid)
        {
            string fxml =
                @"<fetch mapping='logical' version='1.0'>" +
                 "<entity name='task'>" +
                  "<attribute name='activityid' />" +
                  "<attribute name='description' />" +
                  "<attribute name='ownerid' />" +
                  "<attribute name='scheduledend' />" +
                  "<attribute name='statecode' />" +
                  "<attribute name='subject' />" +
                      "<filter>" +
                                "<condition attribute='regardingobjectid' operator='eq' value='" + _opportunityid + "' />" +
                      "</filter>" +
                    "</entity>" +
                "</fetch>";

            FetchXmlToQueryExpressionRequest fxmlReq = new FetchXmlToQueryExpressionRequest() { FetchXml = fxml };
            FetchXmlToQueryExpressionResponse expression = (FetchXmlToQueryExpressionResponse)service.Execute(fxmlReq);

            var request = new RetrieveMultipleRequest { Query = expression.Query };
            EntityCollection entityList = ((RetrieveMultipleResponse)service.Execute(request)).EntityCollection;
            return entityList;

        }

No comments:

Post a Comment