locked
Changing From field in email activity to type Contact - CRM 4 RRS feed

  • Question

  • Hi all,

     

    Is there a way to programmatically change this type to Contact? A the moment there is only of type User and Queue.

    My situation is that I have to process a text file of a couple of hundred records each time and create them as email activities.

    Each of them have to created such that the From field is pointing to a contact record in CRM.

    I am developing a C# app to do this

    Is this possible?

    Thanks,


    • Edited by Stanley_Lai Monday, November 21, 2011 7:28 AM
    Monday, November 21, 2011 6:30 AM

Answers

  • Thanks SAm,

    I was able to do test this out myself without changing the direction.

    Here is my code:

     

    service = new CrmService();

                service.Credentials = System.Net.CredentialCache.DefaultCredentials;

                    email message = new email();

                    activityparty to = new activityparty();

                    activityparty from = new activityparty();

                    to.partyid = new Lookup();

                    from.partyid = new Lookup();

     

                    message.subject = "TEST01";

     

     

                    from.partyid.type = EntityName.contact.ToString();

                    from.partyid.Value = new Guid("D7870B4A-8100-DE11-B472-005056BA3050");

                    to.partyid.type = EntityName.systemuser.ToString();

                    to.partyid.Value = new Guid("EDAA1F9A-F213-E111-A0BE-005056803E1E");

     

                    message.to = new activityparty[] { to };

                    message.from = new activityparty[] { from };

                    Guid emailid = service.Create(message);

    • Marked as answer by Stanley_Lai Monday, November 21, 2011 9:54 AM
    Monday, November 21, 2011 9:54 AM

All replies

  • The To and From fields are tied with the Direction field. If it is an incoming mail, you can tie the from to Contact/Account. But if you want to record it as an out-going mail you can only select system user. This is because only users of CRM can send mails from CRM.

    In your code, set the direction code and then you can assign Contact to the from field.

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Monday, November 21, 2011 9:27 AM
    Monday, November 21, 2011 9:27 AM
  • Thanks SAm,

    I was able to do test this out myself without changing the direction.

    Here is my code:

     

    service = new CrmService();

                service.Credentials = System.Net.CredentialCache.DefaultCredentials;

                    email message = new email();

                    activityparty to = new activityparty();

                    activityparty from = new activityparty();

                    to.partyid = new Lookup();

                    from.partyid = new Lookup();

     

                    message.subject = "TEST01";

     

     

                    from.partyid.type = EntityName.contact.ToString();

                    from.partyid.Value = new Guid("D7870B4A-8100-DE11-B472-005056BA3050");

                    to.partyid.type = EntityName.systemuser.ToString();

                    to.partyid.Value = new Guid("EDAA1F9A-F213-E111-A0BE-005056803E1E");

     

                    message.to = new activityparty[] { to };

                    message.from = new activityparty[] { from };

                    Guid emailid = service.Create(message);

    • Marked as answer by Stanley_Lai Monday, November 21, 2011 9:54 AM
    Monday, November 21, 2011 9:54 AM
  • Thanks SAm,

    I was able to do test this out myself without changing the direction.

    Here is my code:

     

    service = new CrmService();

                service.Credentials = System.Net.CredentialCache.DefaultCredentials;

                    email message = new email();

                    activityparty to = new activityparty();

                    activityparty from = new activityparty();

                    to.partyid = new Lookup();

                    from.partyid = new Lookup();

     

                    message.subject = "TEST01";

     

     

                    from.partyid.type = EntityName.contact.ToString();

                    from.partyid.Value = new Guid("D7870B4A-8100-DE11-B472-005056BA3050");

                    to.partyid.type = EntityName.systemuser.ToString();

                    to.partyid.Value = new Guid("EDAA1F9A-F213-E111-A0BE-005056803E1E");

     

                    message.to = new activityparty[] { to };

                    message.from = new activityparty[] { from };

                    Guid emailid = service.Create(message);

    Hi Stanzarectah/Sam,

    I know this is an old post, but in case you happen to view it, please answer - Will it not be a problem if you write a code to auto populate Contact in a lookup meant for User/Queue? I mean you may be able to populate it, but does it save? And post saving, when you reopen the record, is the Contact still populated there or it shows blank? Can you pull a report using this data?

    Regards,

    Yogesh

    Tuesday, November 25, 2014 10:54 AM