Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

Fetching Phone Call record based on Sender and Recipient in CRM 2011

$
0
0

My motive is to fetch a Phone Call record based on the combination of the following inputs :

  • Sender
  • Recipient
  • Phone
  • Due

Now Sender and Recipient are of type PartyList in CRM 2011.

I have written the following code, but PartyList seems to spoil the mood.

bool searchFlag = false;
            ColumnSet attributeSet = new ColumnSet("from", "to", "phonenumber", "scheduledend");

            FilterExpression filterExpression = new FilterExpression();
            filterExpression.FilterOperator = LogicalOperator.And;

            if (!string.IsNullOrEmpty(crmRequestEntity.Entity_Activity_Sender))
            {
                filterExpression.Conditions.Add(new ConditionExpression()
                {
                    AttributeName = "from",
                    Operator = ConditionOperator.Equal,
                    Values = { new Guid(crmRequestEntity.Entity_Activity_Sender) }
                });

                searchFlag = true;
            }

            if (!string.IsNullOrEmpty(crmRequestEntity.Entity_Activity_Recipient))
            {
                filterExpression.Conditions.Add(new ConditionExpression()
                {
                    AttributeName = "to",
                    Operator = ConditionOperator.Equal,
                    Values = { new Guid(crmRequestEntity.Entity_Activity_Recipient) }
                });

                searchFlag = true;
            }

            if (!string.IsNullOrEmpty(crmRequestEntity.Entity_Activity_Phone))
            {
                filterExpression.Conditions.Add(new ConditionExpression()
                {
                    AttributeName = "phonenumber",
                    Operator = ConditionOperator.Equal,
                    Values = { crmRequestEntity.Entity_Activity_Phone }
                });

                searchFlag = true;
            }

            if (!string.IsNullOrEmpty(crmRequestEntity.Entity_Activity_Due))
            {
                filterExpression.Conditions.Add(new ConditionExpression()
                {
                    AttributeName = "scheduledend",
                    Operator = ConditionOperator.Equal,
                    Values = { crmRequestEntity.Entity_Activity_Due }
                });

                searchFlag = true;
            }

            if (!searchFlag)
            {
                throw new Exception("Search Criteria Required");
            }

            QueryExpression query = new QueryExpression()
            {
                EntityName="phonecall",
                ColumnSet = attributeSet,
                Criteria = filterExpression
            };

            try
            {
                IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri(CRM_SERVICE_URL));
                var creds = new ClientCredentials();
                creds.Windows.ClientCredential = new NetworkCredential(SERVICE_ACCOUNT_USERNAME, SERVICE_ACCOUNT_PASSWORD, SERVICE_ACCOUNT_DOMAIN);

                using (_serviceProxy = new OrganizationServiceProxy(orgConfigInfo, creds))
                {
                    EntityCollection result = new EntityCollection();
                    result = _serviceProxy.RetrieveMultiple(query);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Activity Fetch Failed");
            }

I am getting the following error:

Cannot add attribute from of type partylist in a condition

Could someone help me out with some code sample please? Thanks.



Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>