locked
Adding Email Queue Item to Queue from Contact - How can i put the Contact in From Field? RRS feed

  • Question

  • Hi Guys,

    A contact completes our webform on our website. The comments box text on the webform goes into a hidden comments box on the contact form which in turn triggers a workflow to create an email message and queue item which adds the email message to a queue for a response from one of the sales team. I am unable to populate the 'From' field on the email message with the Regarding Contact or Contact details in order for me to be able to just hit reply to answer the query.

    Any ideas on how i can acheive this?

    Thanks
    Dave


    David Kelly

    Friday, September 26, 2014 3:15 PM

All replies

  • Hi David,

    From and To fields on Email Activity are of type 'Activity Party'. You cannot directly associate Regarding to these fields but have to build an activity party list from contact/ account and then assign this activity party list.

    Please refer to this article on MSDN for more 


    Hope this helps. Amar

    CRM Forum Guidance on how to Help Us Help You

    Sunday, September 28, 2014 7:54 AM
  • Thanks alot Amar,

    Does this mean i can't do it through a workflow? Would I have to get the IT guys to create some code as per the link you supplied?

    Dave


    David Kelly

    Monday, September 29, 2014 2:38 PM
  • yes that is correct that could be a custom activity that can be used in a worklfow to create email and assign it to a queue or a plugin to create an email and assign it to a queue.


    Hope this helps. Amar

    CRM Forum Guidance on how to Help Us Help You

    Wednesday, October 1, 2014 3:35 PM
  • Hi  David using Custom Workflow you can achieve this . Below is the sample code.

    protected override void Execute(CodeActivityContext executionContext)
            {
                //Create the tracing service
    
                try
                {
                    //Create the context
                    IExecutionContext context = executionContext.GetExtension<IExecutionContext>();
                    IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                    ITracingService tracer = executionContext.GetExtension<ITracingService>();
    
                    bool isEmailmatches = false;
                    EntityReference incident = EmailActivityLookup.Get(executionContext);
    
                    RetrieveRequest request = new RetrieveRequest();
                    request.ColumnSet = new ColumnSet(new string[] { "from", "description", "subject" });
                    request.Target = new EntityReference("email", incident.Id);
    
                    string email = string.Empty;
                    string senderqueue = string.Empty;
                    string senderqueueFOC = string.Empty;
    
                    bool senderqueueOutput = false;
                    bool senderqueueOutputFOC = false;
    
    
                  
               
    
                 
                    Guid SenderQueueId = Guid.Empty;
    
    
                 
    
                    Entity entity = (Entity)((RetrieveResponse)service.Execute(request)).Entity;
    
                      
                   
    
    
                    EntityCollection IncommingParty = null;
    
    
                    IncommingParty = (EntityCollection)entity["from"];
    
    
                
    
    
                    for (int i = 0; i < IncommingParty.Entities.Count; i++)
                    {
    
                        if (IncommingParty != null && IncommingParty[i].LogicalName
                         == "activityparty")
                        {
                            EntityReference PartyReference =
                            (EntityReference)IncommingParty[i]["partyid"];
    
    
                            // Checking if email is sent by CRM Account 
                            if (PartyReference.LogicalName == "systemuser")
                            {
                                // Retrieve sender Account record 
                                Entity User = service.Retrieve("systemuser",
                                PartyReference.Id, new ColumnSet(true));
    
                                // wod_Account = new Entity("account");
                                email = User.Attributes["internalemailaddress"].ToString();
    
    
                                if (email.Contains("HotAlerts@QTHotAlerts.com") == true)
                                {
                                    senderqueue = "Tier 1 Email";
    
    
    
                                }
    
                                if (email.Contains("ford.com") == true)
                                {
                                    
                                    senderqueue = "Tier 1 Email";
    
    
                                }
    
                                if (email.Contains(".ca") == true)
                                {
                                  
    
                                    senderqueueFOC = "FOC Tier 1 Email - English ";
    
    
                                }
    
                                if (email.Contains("icollection.com") == true)
                                {
                                    senderqueue = "Tier 1 Email";
    
                                }
    
    
    
                            }
    
    
                        }
    
    
    
    
    
    
                    }
                   
    
    
    
                    QueryByAttribute querybyattribute2 = new QueryByAttribute("queue");
                    querybyattribute2.ColumnSet = new ColumnSet("name", "queueid");
    
                    querybyattribute2.Attributes.AddRange("name");
    
                    //  Value of queried attribute to return.
                    querybyattribute2.Values.AddRange(senderqueue);
                    
                    EntityCollection retrieved2 = service.RetrieveMultiple(querybyattribute2);
    
                    foreach (var c in retrieved2.Entities)
    
                    // string Queueid = c.Attributes.Contains("queueid").ToString();
                    {
                       SenderQueueId = c.GetAttributeValue<System.Guid>("queueid");
    
    
                    }
    
    
    
                    if (senderqueue != null && senderqueue != string.Empty)
                    {
    
    
                        senderqueueOutput = true;
    
                    }
    
    
    
                    if (senderqueueFOC != null && senderqueueFOC != string.Empty)
                    {
    
    
                        senderqueueOutputFOC = true;
    
                    }
    
    
    
    
    
    
    
                    this.OutSenderSearchFOC.Set(executionContext, senderqueueOutputFOC);
    
                    this.OutSenderSearch.Set(executionContext, senderqueueOutput);
    
               
    
    
                }
    
                catch (Exception ex)
                {
                    Helpers.Throw(String.Format("An error occurred in the {0} Workflow.",
                            this.GetType().ToString()),
                          ex);
                }
    
            }
    
            [ReferenceTarget("email")]
            [Input("EmailActivity")]
            public InArgument<EntityReference> EmailActivityLookup { get; set; }
    
                  
    
    
    
    
    
            [Output("OutSenderSearch")]
            public OutArgument<bool> OutSenderSearch { get; set; }
    
    
            [Output("OutSenderSearchFOC")]
            public OutArgument<bool> OutSenderSearchFOC { get; set; }
    
    
    
    
    
    
    
    
          
    
    
        }
    
    
    
    }
    
    
    
    
    
    
    
    

    Here i am doing many things but you can see how to rerieve data from  activity party. Please let me know for any clarification.


    Abhishek

    • Proposed as answer by Abhisinha17 Thursday, January 22, 2015 6:24 AM
    • Unproposed as answer by Abhisinha17 Thursday, January 22, 2015 6:25 AM
    Thursday, October 2, 2014 7:20 AM
  • Great thanks alot Abhishek. Will pass along to the IT guys for a look.

    Thanks
    Dave


    David Kelly

    Monday, October 13, 2014 2:44 PM
  • Hi David,

    If my solution helped please propose as a answer.

    Thanks,

    Abhishek


    Abhishek

    • Proposed as answer by Abhisinha17 Monday, February 23, 2015 9:24 AM
    Thursday, January 22, 2015 6:25 AM
  • Hi,

    How are you handling the email considering that when you create an email it's sent, isn't it?

    Regards


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Thursday, January 22, 2015 7:51 AM