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...
Solved! Go to Solution.
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.
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!
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.
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 |
---|---|
77 | |
26 | |
20 | |
16 | |
15 |
User | Count |
---|---|
145 | |
44 | |
44 | |
33 | |
30 |