locked
Changing the From field value in an incoming E-mail RRS feed

  • Question

  • Hi

    I'm having trouble changing the from field on an incoming email.

    The scenario is that if I receive an email from a customer that hasn't got a record in CRM, I want to create a customer and set the from field on the email activity to that customer. 

    I have a plugin registered on pre-validation that fires, creates the new customer and attempts to set the from field.  The from field is an party list field, and I believe there is a problem updating party lists in the pre-validation step (from this http://mscrmuk.blogspot.co.uk/2011/07/partylist-attributes-and-plugin-event.html).

    The code I have to create the customer and update the party list is as follows:

    // Create a new customer
    conId = CreateNewCustomer(localContext, entity);
    
    // Update the email with the newly created customer                                    
    Entity fromParty = new Entity("activityparty");
    fromParty["partyid"] = new EntityReference("contact", conId);                                    
     entity["from"] = new EntityCollection( new List<Entity>(){ fromParty } );

    I've also tried this in the pre-validation stage but the plugin just doesn't fire.

    Any thoughts on how to do this?

    Wednesday, June 12, 2013 3:04 PM

Answers

  • I actually solved this by using CRMs inbuilt facility to create customers automatically (Personal Options->Email) and then using a pre-create plugin on the newly created customer to populate some required fields.

    • Marked as answer by Col Lowe Thursday, June 13, 2013 3:33 PM
    Thursday, June 13, 2013 3:33 PM

All replies

  • Which message are you using to register this plugin ?


    Thanks Satish Reddy http://Learn-Dynamics.com

    Wednesday, June 12, 2013 3:11 PM
  • normally to a partylist attribute you need to set an array of entity, like this:

    Entity[] arrayFrom = { fromParty };
    entity["from"] = arrayFrom;

    can you try this code?
    the contact is created or fails also the creation of the contact?
    did you try to set an existing contact as "from" to check if that part is working?


    My blog: www.crmanswers.net

    Wednesday, June 12, 2013 3:12 PM
  • Hi Satish

    It's currently on Create on the email entity at the Pre-operation stage.

    Have tried it on pre-validation stage but plugin doesn't fire

    Have tried it on post-operation but then the email is locked and you can't update.

    Colin.

    Wednesday, June 12, 2013 3:15 PM
  • Hi Guido, thanks for your help

    I tried the array of entity code and got the same results.

    The contact is definately created because I create a Case at the same time and this has the Customer set correctly as the new customer.

    If I set the partyid to an existing customer's guid then I get the same result which I guess means that the changes to the from are being ignored. 

    Wednesday, June 12, 2013 4:15 PM
  • I actually solved this by using CRMs inbuilt facility to create customers automatically (Personal Options->Email) and then using a pre-create plugin on the newly created customer to populate some required fields.

    • Marked as answer by Col Lowe Thursday, June 13, 2013 3:33 PM
    Thursday, June 13, 2013 3:33 PM