Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

'Contact' entity doesn't contain attribute with Name =

$
0
0

The below is the code that I am using in my workflow but when I run it I keep getting the following error:

"'Contact' entity doesn't contain attribute with Name = "

In my code I am reading in teh last 9 digits of a mobile phone nember and then checking this 9 digits against a MobilePhone field in the 'Contact' entity.

Anyone any ideas what the probelm is?

// <copyright file="CheckMobile.cs" company="">
// Copyright (c) 2014 All Rights Reserved
// </copyright>
// <author></author>
// <date>3/19/2014 4:20:42 PM</date>
// <summary>Implements the CheckMobile Workflow Activity.</summary>
namespace CheckMobileNumber.Workflow
{
    using System;
    using System.Activities;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Workflow;
    using Microsoft.Xrm.Sdk.Query;
    using Microsoft.Xrm.Sdk.Client;
    using System.Linq;

    public sealed class CheckMobile : CodeActivity
    {
        /// <summary>
        /// Executes the workflow activity.
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Create the tracing service
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();

            if (tracingService == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");
            }

            tracingService.Trace("Entered CheckMobile.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",
                executionContext.ActivityInstanceId,
                executionContext.WorkflowInstanceId);

            // Create the context
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

            if (context == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");
            }

            tracingService.Trace("CheckMobile.Execute(), Correlation Id: {0}, Initiating User: {1}",
                context.CorrelationId,
                context.InitiatingUserId);

            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); 

 try
            {
                // TODO: Implement your custom Workflow business logic.
                
                var MobileCheck = this.MobiletoQuery.Get(executionContext);

                var querycontact = new QueryExpression()
                {
                    EntityName = Contact.EntityLogicalName,                    
                    ColumnSet = new ColumnSet(allColumns: true),
                    Criteria = new FilterExpression()
                };

                //look for a contact with the mobile number provided
                
                
                string input = this.MobiletoQuery.Get(executionContext);
                
                string mobStr = input.Substring(input.Length-9);
                                
                
                querycontact.Criteria.AddCondition(mobStr, ConditionOperator.Like, MobileCheck);

                var contactrecords = service.RetrieveMultiple(querycontact);
                //if there is no match
                if (contactrecords.Entities.Count < 1)
                {
                    //the contact doesn't exist so we have to create one
                    var thenewcontact = new Contact()
                    {
                        FirstName = "Name",
                        LastName = "Unspecified",
                        MobilePhone = MobileCheck,
                        Id = new Guid()
                    };
                }

            }
            catch (FaultException<OrganizationServiceFault> e)
            {
                tracingService.Trace("Exception: {0}", e.ToString());

                // Handle the exception.
                throw;
            }

            tracingService.Trace("Exiting eServicesMobileToCase.Execute(), Correlation Id: {0}", context.CorrelationId);
        }
      }
     }
  }


Viewing all articles
Browse latest Browse all 8223

Trending Articles



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