Показать сообщение отдельно
Старый 05.03.2024, 15:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,477 / 846 (79) +++++++
Регистрация: 28.10.2006
crmtipoftheday: Tip #1446: Empty array in Power Automate
Источник: https://crmtipoftheday.com/1446/empt...power-automate
==============

To create an empty array in a Power Automate formula, just use json('[]'). That’s it — there’s your entire tip.

But when might you need this? Let’s say you’re working with the same third-party service as I did the other day. The service returns an array of objects, and you need to loop through the returned objects. Now, if no objects are found, a well-designed service would typically return an empty array. But this one? It returns null. Bleugh. You could add an if action, but there’s a neater solution. Use the following formula in the ‘Apply to each’ action:

coalesce( outputs('Custom_Service')?['body/value'], json('[]') )
This approach uses the coalesce function to check the output from the custom service, and if it’s null, it falls back to an empty array, thanks to json('[]'). Empty array means the loop is simply not executed which is exactly what we wanted.

Cover Image by Andrew Martin from Pixabay.



Источник: https://crmtipoftheday.com/1446/empt...power-automate
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.