Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Import records from email attachment in Microsoft dynamics CRM

Posted on by Microsoft Employee

Hi, 

I'm a newbie to MS Dynamics and want to implement a feature which can extract the records from incoming attachment and insert them into a custom entity. 

I got a post here to create a new record if the email with attachment is received but I need that attachment to be extracted (if it is .csv) and then the rows to be inserted/updated in Dynamics for a custom entity. 

If there any built-in capabilities from where I can start? Can anybody please guide me to do this?

 

Appreciate your help in advance. 

Thanks, 

Sandip

*This post is locked for comments

  • Suggested answer
    Abby Kong Profile Picture
    Abby Kong 6 on at
    RE: Import records from email attachment in Microsoft dynamics CRM

    Hi Sandip,

    • For email attachment, you can use field body in entity activitymimeattachment
    • For file attachment in note, you can use field documentbody in entity annotation

    Since your file is CSV file,  it can programmatically be processed easily, first use below code to retrieve the content:

            Entity attachment = service.Retrieve("activitymimeattachment", attachmentId, new ColumnSet("body")); //include filename column if you need it
            string documentBody = DecodeBase64((string)attachment["body"]);
    
            public static string DecodeBase64(string base64EncodedData)
            {
                var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
                return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
            }


    After the retrieving of csv content, if you have any csv library, that's great. Otherwise, you can: 

    string[] lines = documentBody.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
    foreach (string line in lines)
    {
          // Implement your logic of what to do with each line
    }


    Regards,

    Abby

  • Suggested answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,265 on at
    RE: Import records from email attachment in Microsoft dynamics CRM

    Maybe this is what you are looking for:

    blogs.msdn.microsoft.com/.../how-to-import-attachments-programmatically

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans