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.
Then I have the necessary loops for the Project Terms custom entity and the Notes entity to populate the email.
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.
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
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.
Solved! Go to Solution.
I figured it out. There was an issue with how I was storing the document. I ended up going a different route.
Hi @Anonymous
I could help you via screenshare? Send me the details via email.
Thanks
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blogHi @Anonymous
I am working on this.
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blogHi @Anonymous
Standard entities and Custom entity attachments are stored under Notes.
Email attachments are stored under Attachments (ActivityMimeAttachment) entity. Here are the steps.
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
Here is my result
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?
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
@LeeHarris any help is appreciated.
Thanks
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blogHi @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.
Follow me on Twitter at @QG_LeeJHarris
Or on LinkedIn at in/leejharris
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.
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blogHi @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
Follow me on Twitter at @QG_LeeJHarris
Or on LinkedIn at in/leejharris
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
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blogHi @abm
I have just tried this with the Common Data Service connector and I am seeing 2 options for Attachments in the drop down.
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".
Follow me on Twitter at @QG_LeeJHarris
Or on LinkedIn at in/leejharris
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
If you liked my response, please consider giving it a thumbs up
Proud to be a Flownaut!
Learn more from my blogI'll be updating the OP with screenshots of what I'm doing after our planning meeting this morning.
I figured it out. There was an issue with how I was storing the document. I ended up going a different route.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Announcing a new way to share your feedback with the Power Automate Team.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
User | Count |
---|---|
72 | |
22 | |
17 | |
17 | |
14 |
User | Count |
---|---|
125 | |
35 | |
30 | |
28 | |
26 |