Before applying this solution, it is important to review this approach
from the security perspective because the security roles of the users in
Dataverse does not apply to the permissions of the SharePoint
folders. If there are confidential emails in Dataverse which should only be seen
by the users with specific role and the attachments are stored in
SharePoint, the files will be exposed to any SharePoint user who has access
to the folder. In such scenario, third party solutions like CB Replicator
are recommended to restrict the access of the SharePoint folder.
If you are looking for a solution to move the email attachments to
the SharePoint document folder of the Regarding row (record), check
out this blog post by
Amey Holden. If you are looking for a solution to
move the notes attachments to SharePoint
and
delete the notes attachments using a cloud flow, Priyesh Wagh
got those covered in his blog posts. If you are looking for a solution to
move an attachment from file column of Dataverse to SharePoint, check out
my
previous blog post here.
After that, add the Documents subgrid to the Email form.
The flow will be triggered on create of an Email row (e.g. when the email is
created with “Received” Status Reason) and when the Status Reason is
updated (e.g. when the draft email is changed to “Pending Send” and
then, “Sent”). The value in Filter rows means the flow will be
triggered only when the value of the Status Reason column is Completed,
Sent, Received or Cancelled.
(statuscode eq 2 or statuscode eq 3 or statuscode eq 4 or statuscode eq 5)
Normally the SharePoint folder name set by the out-of-the-box SharePoint
integration is the combination of the primary name value of the row and the GUID
of the row. For this case, the primary name value would be the email subject and
it may contain invalid characters which are not accepted as the folder name in
SharePoint. That is the reason why special characters need to be removed before
setting the email subject as a SharePoint folder name. To remove the special
characters, I used the approach mentioned in
this blog post
by Fredrik Engseth and modified it a bit.
createArray('.','@','ß','²','³','µ','`','´','°','^','=','(',')','&','$','§', '~','#','%','*',':','<','>','?','/','|',' ', ' ','{','}','!','+','__','___')
indexOf(variables('Email Subject'), item())
replace(variables('Email Subject'),item(),'_')
The SharePoint folder name for the email will be used in multiple places of
the flow so that a Compose step is created to store the Folder Name. The
folder name will be a combination of email subject without special characters
and the GUID of the email row without ‘-‘ (removed by using the following
expression).
toUpper(replace(triggerOutputs()?['body/activityid'], '-', ''))
first(outputs('List_SharePoint_Site_-_URL')?['body/value'])?['absoluteurl']
relativeurl eq 'email' and startswith(parentsiteorlocation_sharepointsite/absoluteurl, 'http')
first(outputs('List_Document_Location_-_Parent_Document_Location_for_Email')?['body/value'])?['sharepointdocumentlocationid']
To move the attachments, retrieve the attachments related to the email and
only the following three columns are required (activitymimeattachmentid,
filename, body). For each attachment file, create a file in the SharePoint
folder under the site address value from step 1, email library
and folder path from the output of the Compose step. The file name is
from the List Rows query and the attachment body needs to be converted from
Base64 to Binary.
base64ToBinary(items('Apply_to_each_Attachment')?['body'])
Original Post http://linnzawwin.blogspot.com/2022/02/automatically-move-dataverse-email.html