cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Medoomi
Helper V
Helper V

Retrieve Dataverse attachments - Error on "Null" attachment(s) after deletion

I have a working Flow which retrieves multiple attachments associated with a single record in a "Projects" Table. These attachments are saved in the Note Table in Dataverse.

After filtering the Note Table, I am using a Compose data operation to import these attachments using the following code:

 

{
  "Name": @{items('Apply_to_each_3')?['filename']},
  "ContentBytes": @{base64ToBinary(items('Apply_to_each_3')?['documentbody'])}
}

 

The output is then appended to an array variable.

 

Everything works fine, except when one of those attachments has been deleted (in a powerapps form where those attachments are displayed). When this happens, the record (for the deleted attachment) in the Notes Table seems to remain, only the output is "Null", which causes the base64ToBinary conversion to fail & the entire flow fails. For example in a record where two attachments remain, and one of those attachments has previously been deleted, the "apply to each_3" step attempts to run three times (instead of two). Two of those steps work, one of them fails with "Null" as the output.

 

If it helps, I am retrieving attachments by filtering the Notes Table with the following code (filtering by GUID of the projects Table):

 

_objectid_value eq @{items('Apply_to_each_2')?['cr6a2_projectid']}

 

 

How can I solve this? I imagine I would either have to avoid creating attachments in the Notes Table with Null as the content, or avoid retrieving those attachments with Null as the content...

1 ACCEPTED SOLUTION

Accepted Solutions
Medoomi
Helper V
Helper V

OK, the answer was simpler than I expected. I took the advice in the Microsoft document Getting errors with null fields. All I needed was a condition action to exclude null values from the output of the filtered Note Table.

View solution in original post

2 REPLIES 2
Medoomi
Helper V
Helper V

Given that the flow breaks at the base64ToBinary step, I attempted to write an if clause which would by-pass the base64ToBinary step if the content was 'Null.' My code was as follows:

{
  "Name": @{items('Apply_to_each_3')?['filename']},
  "ContentBytes": @{if(equals(items('Apply_to_each_3')?['documentbody'],'Null'),'Null',base64ToBinary(items('Apply_to_each_3')?['documentbody']))}
}

It seems the if clause still doesn't by-pass the base64ToBinary step because my error output is as follows:

InvalidTemplate. Unable to process template language expressions in action 'Compose_All_Attachments' inputs at line '0' and column '0': 'The template language function 'base64ToBinary' expects its parameter to be a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#base64ToBinary for usage details.'.

Is there another way to by-pass the base64ToBinary step when the content is 'Null'

Or another way to circumvent this problem?

Thanks!

Medoomi
Helper V
Helper V

OK, the answer was simpler than I expected. I took the advice in the Microsoft document Getting errors with null fields. All I needed was a condition action to exclude null values from the output of the filtered Note Table.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Users online (4,116)