email to case - customer field RRS feed

  • Question

  • I have created a workflow for creating a case whenever an email is recieved to a specific queue. I have gotten everything working correctly except for the customer field within the case. I need the customer field to match the customer that sent the email but it only goes to the default customer.
    Wednesday, January 13, 2010 6:55 PM


All replies

  • Wednesday, January 13, 2010 9:33 PM
  • will this work with contacts as well as accounts?
    Wednesday, January 13, 2010 9:59 PM
  • this one only works with account...following is the custom workflow code for contact..

    so once you have account and contact workflow...then in workflow editor use them as per your requirments..let me know if you need more informations..

    	[CrmWorkflowActivity("Find Contact with specified email address")]
    	public class MatchSenderWithContact : System.Workflow.Activities.SequenceActivity 
    		public static DependencyProperty senderProperty = DependencyProperty.Register("sender", typeof(string), typeof(MatchSenderWithContact));
    		public string sender
    			get { return (string)base.GetValue(senderProperty); }
    			set { base.SetValue(senderProperty, value); }
    		 //// Output property  
    		public static DependencyProperty contactIdProperty = DependencyProperty.Register("contactId", typeof(Lookup), typeof(MatchSenderWithContact));
    		 public Lookup contactId
    			 get { return (Lookup)base.GetValue(contactIdProperty); }
    			 set { base.SetValue(contactIdProperty, value); }
    		private Guid MatchSenderWithExistingContact(ICrmService crmService, string fromAddress)
    			// Retrieve accounts with this email address.
    			QueryByAttribute query = new QueryByAttribute();
    			query.EntityName = EntityName.contact.ToString();
    			query.Attributes = new string[] { "emailaddress1" };
    			query.Values = new string[] { fromAddress };
    			RetrieveMultipleRequest retrieveMultipleRequest = new RetrieveMultipleRequest();
    			retrieveMultipleRequest.Query = query;
    			retrieveMultipleRequest.ReturnDynamicEntities = true;
    			RetrieveMultipleResponse retrieveMultipleResponse = (RetrieveMultipleResponse)crmService.Execute(retrieveMultipleRequest);
    			Guid contactId = Guid.Empty;
    			foreach (BusinessEntity busEntity in retrieveMultipleResponse.BusinessEntityCollection.BusinessEntities)
    				// Pick the first contactid.
    				contactId = ((Key)(((DynamicEntity)busEntity)["contactid"])).Value;
    			return contactId;
    		protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) 
    		 IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService)); 
    		 IWorkflowContext context = contextService.Context;
    		 // Obtain IcrmService so we can call into CRM SDK to retrieve 
    		 // accounts                
    		 ICrmService crmService = context.CreateCrmService();
    		 // this.sender property will have the email address that needs to be matched.
    		 //Guid accountId = MatchSenderWithExistingAccount(crmService, this.senderContact);
    		 Guid contactId = MatchSenderWithExistingContact(crmService, this.sender);
    		 // Set the accountId output property to return this data
    		 // back to the calling workflow
    		 //this.accountId = new Lookup("account", accountId);
    		 this.contactId = new Lookup("contact",contactId);
    		 return ActivityExecutionStatus.Closed;
    Wednesday, January 13, 2010 10:05 PM