Remove returns from note attachment in Dynamics 365
Typewriter from archives.gov

Remove returns from note attachment in Dynamics 365

In a project I’m working on, I noticed that images that were uploaded with the Dynamics 365 Field Service mobile app aren’t stored correctly in Dynamics. The images appear to have been stored with carriage returns in the code. The weird thing is that for the users it looks like a normal picture and Dynamics processes it as a normal picture, but if you use another tool like Smart Flows by Xpertdoc the picture appears to be corrupt. Users get the error message that there’s invalid character, sometimes a ‘d’ and sometimes an ‘a’, when generating a report. Both support desks of Microsoft and Xpertdoc don’t seem to be able to help us with this, so we needed to solve it ourselves.

First, let me explain what a carriage return is. Thing of the typewriter in the old days, you needed to push a lever to go to the beginning of the next line. The typewriter than moves the carriage (these days, this is the cursor) to that position. Maybe you know of the pling-sound that is makes in that case. A normal return is when you go the next line, but you stay on the same vertical position. So, why do we need this in a picture file? Well, we don’t. A picture is just one line with code. It’s just converted this way when storing the uploaded picture in Dynamics. This doesn’t happen when you take the picture directly in the app.

I solved it by updating the picture in Dynamics via Power Automate cloud flow. The flow is triggered by the creation of a Note in Dataverse.

Power automate flow trigger at creation of a note in Dataverse

 Then I added a condition that checks if the attachment is in fact a jpeg-picture and it contains a carriage return or a normal return. The issue is just with jpeg-pictures and not with other documents and I only want to update where it’s necessary. The carriage return appears as \r and the normal return (new line) show as \n in the code. You can’t find or remove them by those characters. Instead, you need to remove them by the function decodeUriComponent(). The function for a carriage return is:

decodeUriComponent('%0D')

And the function for the normal return is:

decodeUriComponent('%0A')

This explains the error reason for the invalid character ‘d’ and ‘a’.

Power automate flow condition note attachment is jpeg and contains return

 If the Note attachment is jpeg and contains return, you update the code of the picture. The code is stored in the Document column. I used the following expression to remove both returns in the code:

replace(replace(triggerOutputs()?['body/documentbody'],decodeUriComponent('%0D'),''),decodeUriComponent('%0A'),'')
Remove returns from note attachment in Power Automate flow

 I hope this article helps you until Microsoft or Xpertdoc has solved this problem.

To view or add a comment, sign in

Others also viewed

Explore content categories