web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to return an empty...
Power Automate
Unanswered

How to return an empty array within an if function so union function won't complain

(0) ShareShare
ReportReport
Posted on by 396

Hi,

Let me explain my question in detail:

I have a flow that runs every time I receive an email, and I want to save every email that is inside the From, To and CC fields.
So I made a variable of type object, so I don't need a ton of initialize variable actions.
This variable has a bunch of properties, and one of them will hold that list of emails that I want to save.

For this I made a large formula that sets the property to a union of multiple arrays so all emails are merged inside 1 array.
Problem is that the To and CC field is a string with multiple emails inside with ";" as the separator.
So this is the formula I had to come up with:

 

setProperty(

    variables('Flow Variables'),
    'vEmailUsers',
    union(
        variables('Flow Variables')?['vEmailUsers'],
        createArray(triggerOutputs()?['body/from']),
        split(triggerOutputs()?['body/toRecipients'],';'),
        split(triggerOutputs()?['body/ccRecipients'],';')
    )
)

This function works pretty good until i get an email that has an empty cc...
So the error says that the split function can't have null value for the first parameter.
Hence I was thinking to surround it with an if statement so that if it is empty I would return an empty array.

Except I don't know how...
I tried using createArray() without parameters, but that's not possible, and regular brackets won't work either.

So I am wondering how it could be solved?
Any ideas?

Thanks in advance!

Categories:
I have the same question (0)
  • VictorIvanidze Profile Picture
    13,073 on at

    Use different union() after checking if To or CC or something is empty.

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    You can check if CC is empty, and if so, just use From in its place since you're using union and any duplicate will be removed.

     

     

    union(
     createArray(triggerOutputs()?['body/from']), 
     split(triggerOutputs()?['body/toRecipients'], ';'), 
     if(empty(triggerOutputs()?['body/ccRecipients']), 
     createArray(triggerOutputs()?['body/from']), 
     split(triggerOutputs()?['body/ccRecipients'], ';')
     )
    )

     


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • VictorIvanidze Profile Picture
    13,073 on at

    That's possible To is empty but CC is not empty.

  • Billy Profile Picture
    396 on at

    Hi,

    @VictorIvanidze you are right, I could indeed do an if statement with 2 different unions inside of it.
    Except that @grantjenkins his solution is more practical and efficient and actually was nearly the same as the solution I had except I didn't pass anything in the createArray function.
    That's mainly because I forgot that union automatically removes duplicates, and I could have just added any of the other arrays into it...

    Kinda facepalming here right now lol.

    Nonetheless, thanks guys for your help on this!

    Really appreciate it!

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    @Billy_C @VictorIvanidze brought up a good point about the possibility of the To field being blank if they only used CC. For completeness it should probably be like this:

     

    union(
     createArray(triggerOutputs()?['body/from']), 
     if(empty(triggerOutputs()?['body/toRecipients']), 
     createArray(triggerOutputs()?['body/from']), 
     split(triggerOutputs()?['body/toRecipients'], ';')
     ),
     if(empty(triggerOutputs()?['body/ccRecipients']), 
     createArray(triggerOutputs()?['body/from']), 
     split(triggerOutputs()?['body/ccRecipients'], ';')
     )
    )

     

  • Billy Profile Picture
    396 on at

    Hi @grantjenkins,

    I used to do both checks, but I thought that it wouldn't be necessary since the To field would be a required field?
    After all, an email goes from a person to a person, so from and to would always be filled in.
    Also, it would be weird if to is blank but cc is not blank, as you are basically sending an email to nobody and sending a copy of your message to nobody to someone else...
    But that's my perspective, of course.

    I guess it won't hurt to add an extra check, but then again, it's just weird...

    Nonetheless, thanks for the advice!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard