cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

base64 Decode PDF from Note Entity for Email Attachment

I know from multiple closed questions on this board that in order to attach a PDF that is stored in the CDS Note entity to an email it needs to be base64 decoded. I've tried passing the document body into the base64tobinary function for the Attachment Content in 'Send an email (V2)'. That throws an error because the document body is a JSON object and it's the ContentBytes inside that object that need decoded. However, I also can't parse the JSON because of the '/' that are throughout it. 

 

Any help on how I'm supposed to decode this and add it as an Attachment Content is appreciated. 

 

Edit to add screenshots below:

 

First, I get a list of CDS Note entities that are tied to the Purchase Order custom entity record that I already have through the trigger body. I expect there to only be one Note entity, which is why I have the Top Count = 1. 

Get Notes.png

 

 

Then I have the necessary loops for the Project Terms custom entity and the Notes entity to populate the email. 

CreateEmail.png

 

If I click in the "Attachments Content -" box, I get the following options for the dynamic content. Note that the Document Body does not appear in the list of dynamic content. 

Dynamic content list.png

 

This is the JSON that I get back from the step pulling the Note entity. Notice that in the red box that there are '/' in the JSON which prevents the JSON from being parsed if I wanted to. I have tried using 

base64ToString(items('Apply_to_each_2')?['documentbody']) to decode the ContentBytes like I have seen in past issues on this board. That fails with the error 'Unable to process template language expressions in action 'Send_an_email_(V2)' inputs at line '1' and column '2691': 'The template language function 'base64ToString' was invoked with a parameter that is not valid. The value cannot be decoded from base64 representation.'.' 

Notes Object.png

 

Edit to my edit: It appears that I may be adding the attachment incorrectly to the CDS Note entity in a different Flow. For some reason the 'Attachments Content' does not appear in the Dynamic Content menu when I click in the 'Document' field for adding a new Note entity to CDS. 

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

I figured it out. There was an issue with how I was storing the document. I ended up going a different route. 

View solution in original post

11 REPLIES 11
abm
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous 

 

I could help you via screenshare?  Send me the details via email.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials
abm
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous 

 

I am working on this.

 

 

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials
abm
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous 

 

Standard entities and Custom entity attachments are stored under Notes.

 

Email attachments are stored under Attachments (ActivityMimeAttachment) entity. Here are the steps.

 

image.png

 

Above I have hardcoded the attachment id to get my single attachment against my email.

 

Documentation says we can filter by objectid but I couldn't find the email id (Objectid) under the attachment run history  😞

 

Next we need to get the Filename and content

 

image.png

 

 

Here is my result

 

image.png

 

 

Couple of things I am still looking for is:

 

1. Why Attachment entity doesn't return the objectid which the attachment is related to? Here in our case email id?

https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/entities/activitymimeattachment#BKMK_ObjectId

 

Below is the attachment run history and no objectid (Our case email id) is returned.

 

[
{
"@odata.type": "#Microsoft.Dynamics.CRM.attachment",
"@odata.id": "https://xxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)",
"@odata.etag": "W/\"14863436\"",
"@odata.editLink": "attachments(85f9af51-ba6b-ea11-a811-0022480030d2)",
"mimetype": "application/pdf",
"filename": "InvoiceLaptop.pdf",
"attachmentid@odata.type": "#Guid",
"attachmentid": "85f9af51-ba6b-ea11-a811-0022480030d2",
"filesize": 136928,
"versionnumber@odata.type": "#Int64",
"versionnumber": 14863436,
"body": "JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvQWx0ZXJuYXRlL0RldmljZVJHQi9MZW5ndGggMjU5Mi9OIDM+PnN0cmVhbQp4nJ2Wd1RT2RaHz703vdASIiAl9F4VCCDSO0iRLgohCRAgAUJCsyuiAiOKiDRFkEEBBxwdiowVUSwMir1PkEFEGQdHERXLu9G1Rte8ee/Nm98fZ31rn7P3PbuctS4AFN90jiAbVgBAIBSLwnzcmdExsUz8EIABEeCANQBsTnamW0hIIEDl5+XBzEYPgS",
"Attachment_SyncErrors@odata.associationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/Attachment_SyncErrors/$ref",
"Attachment_SyncErrors@odata.navigationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/Attachment_SyncErrors",
"attachment_activity_mime_attachments@odata.associationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/attachment_activity_mime_attachments/$ref",
"attachment_activity_mime_attachments@odata.navigationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/attachment_activity_mime_attachments",
"userentityinstancedata_attachment@odata.associationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/userentityinstancedata_attachment/$ref",
"userentityinstancedata_attachment@odata.navigationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/userentityinstancedata_attachment"
}
]

 

2. If we have more than one attachment under the same email how can we attach all the documents in one email? I have tried couple of things like declared an object and append the filename and content

{
"Name": "",
"ContentBytes":
}

 

Also tried

 

{
"mime/type": "",
"ContentBytes":
}

 

But no luck at all.

 

I am tagging @LeeHarris  for some help here. Lee has answered the below post regarding attachments

 

https://powerusers.microsoft.com/t5/Building-Flows/Dynamics-365-Use-flow-to-take-an-attachment-from-an-email-on-an/m-p/503150#M62912

 

@LeeHarris  any help is appreciated.

 

Thanks

 

 

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Hi @abm 

Just to clarify my understanding of the issue here. @Anonymous  you are trying to get an attachment from a Note record in CDS and send it in a email?

The content of CDS Note attachments are found in the "documentbody" property of the "annotations" entity. If you know the Note id then you can query annotations in order to get the Note record and the documentbody value. Notes with attachments will have the "isdocument" property set to true so you can use that as well if you want to check that the Note has an attachment before processing it. I don't think that you will need to convert the documentbody value if then attaching to an email, simply use the value, as is, in the Attachment content.

If you are trying to get details on an attachment for an email record then you need to be querying the "activitymimeattachments" entity. You will then have an objectid property which provides the id of the record that the attachment relates to. In addition, this record will also have an "objecttypecode" which indicates the type of record that it relates to. Useful for filters if you only want attachments for a particular activity type returned. The attachmentid in this activitymimeattachments record shows the link to the actual attachment record but the content of "body" in both should be identical, so you only need the activitymimeattachment record.

Hope that helps.

 


Did I answer your question? Mark my post as a solution!

Follow me on Twitter at @QG_LeeJHarris

Or on LinkedIn at in/leejharris

abm
Most Valuable Professional
Most Valuable Professional

Hi @LeeHarris 

 

Thanks for your reply. 

 

For the notes entity I can get all the details as expected. That's no problem at all.

 

Yes for the email attachments it is stored under activitymimeattachment entity.

 

But for the activity activity_mime_attachments I can't see the object id. See below JSON returned from Get All Attachments with no filter.

 

[
{
"@odata.type": "#Microsoft.Dynamics.CRM.attachment",
"@odata.id": "https://xxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)",
"@odata.etag": "W/\"14863436\"",
"@odata.editLink": "attachments(85f9af51-ba6b-ea11-a811-0022480030d2)",
"mimetype": "application/pdf",
"filename": "InvoiceLaptop.pdf",
"attachmentid@odata.type": "#Guid",
"attachmentid": "85f9af51-ba6b-ea11-a811-0022480030d2",
"filesize": 136928,
"versionnumber@odata.type": "#Int64",
"versionnumber": 14863436,
"body": "JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9GaWx0ZXIvRmxhdGVEZWNvZGUvQWx0ZXJuYXRlL0RldmljZVJHQi9MZW5ndGggMjU5Mi9OIDM+PnN0cmVhbQp4nJ2Wd1RT2RaHz703vdASIiAl9F4VCCDSO0iRLgohCRAgAUJCsyuiAiOKiDRFkEEBBxwdiowVUSwMir1PkEFEGQdHERXLu9G1Rte8ee/Nm98fZ31rn7P3PbuctS4AFN90jiAbVgBAIBSLwnzcmdExsUz8EIABEeCANQBsTnamW0hIIEDl5+XBzEYPgS",
"Attachment_SyncErrors@odata.associationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/At...",
"Attachment_SyncErrors@odata.navigationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/At...",
"attachment_activity_mime_attachments@odata.associationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/at...",
"attachment_activity_mime_attachments@odata.navigationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/at...",
"userentityinstancedata_attachment@odata.associationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/us...",
"userentityinstancedata_attachment@odata.navigationLink": "https://xxxxxx.crm11.dynamics.com/api/data/v9.0/attachments(85f9af51-ba6b-ea11-a811-0022480030d2)/us..."
}
]

 

Thanks for your help.

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Hi @abm 

If you run the below query in your browser (replacing the xxxxx with your instance name) you should get the activitymimeattachment record back for the attachment that you are looking at. The body property for this record should match the body value in the attachment record so there is no need to query attachments directly. You should also then have access to the objectid. This activitymimeattachment record is effectively working as the join between both the activity (which could be one of many entity types including email) and the attachment record.

 

https://xxxxx.crm11.dynamics.com/api/data/v9.0/activitymimeattachments?$filter=_attachmentid_value eq  85f9af51-ba6b-ea11-a811-0022480030d2

 


Did I answer your question? Mark my post as a solution!

Follow me on Twitter at @QG_LeeJHarris

Or on LinkedIn at in/leejharris

abm
Most Valuable Professional
Most Valuable Professional

Hi @LeeHarris 

 

Thanks for your reply 🙂

 

May I ask you you try the CDS connector and get all attachments. Why the object id is missing from JSON? Yes the documentation says it and via SDK I can access it using custom code (C#).

 

Is this a limitation in flow CDS connector?

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

Hi @abm 

I have just tried this with the Common Data Service connector and I am seeing 2 options for Attachments in the drop down.

 

image.png

One of these is the attachment entity and the other is the activitymimeattachment entity. You can see from the below responses that only the activitymimeattachment returns the objectid.

 

Attachment

{
  "@odata.context": "https://uk-001.azure-apim.net/apim/commondataservice/ba6154td4b454efc88f3f003e3535326/$metadata#datasets('org654s54af.crm4')/tables('attachments')/items",
  "value": [
    {
      "@odata.id": "https:/instancename.crm4.dynamics.com/api/data/v9.0/attachments(14cfc44a-70ea-e911-a811-000d3ab4d306)",
      "@odata.etag": "",
      "ItemInternalId": "14cfc44a-70ea-e911-a811-000d3ab4d306",
      "versionnumber": 226802206,
      "filename": "image001.jpg",
      "mimetype": "image/jpeg",
      "body": "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/wAALCAAwADABAREA/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEBAAA/APZqKKKKKKKKKKKKKKKKKKKKKKKKKKKKK//9k=",
      "attachmentid": "14cfc44a-70ea-e911-a811-000d3ab4d306",
      "filesize": 359,
      "prefix": null,
      "subject": null
    }
  ]
}

 

ActivityMimeAttachment

{
  "@odata.context": "https://uk-001.azure-apim.net/apim/commondataservice/na6154cb4b454jfc88f3f003e3535326/$metadata#datasets('org111i53af.crm4')/tables('activitymimeattachments')/items",
  "value": [
    {
      "@odata.id": "https://instancename.crm4.dynamics.com/api/data/v9.0/activitymimeattachments(2b516b8d-2785-4e25-953d-000067ec8e07)",
      "@odata.etag": "",
      "ItemInternalId": "2b516b8d-2785-4e25-953d-000067ec8e07",
      "overwritetime": "1900-01-01",
      "attachmentnumber": 1,
      "solutionid": "fd140aae-4df4-11dd-bd17-0019b9312238",
      "_objectid_value": "2eb54855-28a8-e711-ad38-005056c00008",
      "_objectid_type": "emails",
      "activitymimeattachmentidunique": "57b6fa9a-6b6c-4d21-aaa4-185521d7b641",
      "isfollowed": false,
      "activitymimeattachmentid": "2b516b8d-2785-4e25-953d-000067ec8e07",
      "_attachmentid_value": "f71d8710-55ca-e711-8144-e0071b662001",
      "_attachmentid_type": "attachments",
      "ismanaged": false,
      "objecttypecode": "email",
      "componentstate": 0,
      "_componentstate_label": "Published",
      "versionnumber": 25220775,
      "subject": null,
      "attachmentcontentid": null,
      "anonymouslink": null
    }
  ]
}

 

As they both appear the same in the entity selection drop down list, the easiest way to guarantee you are fetching the correct data is to select the custom option (very bottom of the drop down) and type the value "activitymimeattachments".

 


Did I answer your question? Mark my post as a solution!

Follow me on Twitter at @QG_LeeJHarris

Or on LinkedIn at in/leejharris

abm
Most Valuable Professional
Most Valuable Professional

Hi @LeeHarris 

 

Thanks for the clarification. I got mixed up with two Attachments there. Thanks for clarifying this and taking time to show me in a screenshot.

 

Cheers



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials
Anonymous
Not applicable

I'll be updating the OP with screenshots of what I'm doing after our planning meeting this morning.

Anonymous
Not applicable

I figured it out. There was an issue with how I was storing the document. I ended up going a different route. 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (2,510)