locked
'Contact' entity doesn't contain attribute with Name = RRS feed

  • Question

  • 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);
            }
          }
         }
      }
    

    Friday, March 21, 2014 4:05 PM

All replies

  • Hello,

    Did you check if you are using correct fields name while retriving/updating field in contact entity, it seems you are not using correct field name ??


    Our Website | Our Blog | Follow US | My 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.

    Monday, March 24, 2014 6:03 AM
    Moderator
  • Check your fields 

    it showing that contact "name" is incorrect check your attribute schema name.


    ms crm

    Monday, March 24, 2014 10:01 AM
  • the error is here:

    string mobStr = input.Substring(input.Length-9);
    querycontact.Criteria.AddCondition(mobStr, ConditionOperator.Like, MobileCheck);
    
    the first parameter of the condition is the field name, but you put inside the variable the phone number, try with:

    querycontact.Criteria.AddCondition("mobilephone", ConditionOperator.Like, MobileCheck);


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Monday, March 24, 2014 10:12 AM