cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
unimatrix27
Regular Visitor

How to get array elements in a foreach

Hi,

 

this might be a completely newbie question - I am trying to use the template "Create Google Contacts from Office365 Contacts". So far so good, but in office365, the business phone number(s) are represented as array inside a contact item, so the create contact action does not show a business phone number to put into the appropriate field in the google contact. It does not show the values that are "hidden" in arrays at all. 

 

Is there a way to access those values?

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-micsh-msft
Community Support
Community Support

Hi @unimatrix27,

 

Yes, there is a way to access those values.

Under the Inputbox of the work phone number, copy and paste the following:

"@{first(item()?['BusinessPhones'])}"

Which would be able to return the first value of the Business phone numbers specified under your Office 365 Contact.

9.PNG

10.PNG

Some reference:

Workflow Definition Language

If you have any further questions, please post back.

Regards

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @unimatrix27,

 

Yes, it is not editable if we specify Workflow Definition Language in the Actions, with WDL used, the formula is hard-coded within workflow, we need to delete the related action and add it again to edit.

For formula used within the Actions (Like Trigger, Actions based on Connections) added in Microsoft Flow, we use the format below:

"@{formula}"

But if we use Compose Action to phase the dynamic content, we use the format below in the Compose Input:

"@formula"

Using Compose would give us the results without the double quote.

Apologize for that the Contacts saved would have the double quotes, please take a try with the action below:

1. Open the corresponding flow and click Edit,

2. Under hte Apply to each, delete the Google Create a Contact action, add then add two Compose Action, first one rename to Address, and second rename to Phone, with the corresponding formula specified (see image), then add the Contact, use the corresponding Compose output with the Email Address and the Phone box under the Google Contact Action:

18.PNG

This way the Contact would be saved without quotes.(Red underline is newly created, highlighted is older).

Please note that the contacts has a filter under the filter query:

@greater(item()?['DateTimeCreated'], adddays(utcnow(),-1))

Which means if the contacts created time is one day older, it won't be listed as an available data with the filter query Action.

 

19.PNG

If you have any further questions, please feel free to post back.

Regards

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
telu
Microsoft
Microsoft

Hi @unimatrix27,

 

is it the error of "A foreach cannot be nested inside of another foreach"?

foreach.png

Thanks

v-micsh-msft
Community Support
Community Support

Hi @unimatrix27,

 

Yes, there is a way to access those values.

Under the Inputbox of the work phone number, copy and paste the following:

"@{first(item()?['BusinessPhones'])}"

Which would be able to return the first value of the Business phone numbers specified under your Office 365 Contact.

9.PNG

10.PNG

Some reference:

Workflow Definition Language

If you have any further questions, please post back.

Regards

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

THans a lot for your reply. I had no idea that the workflow definition language can be applied at all. This should be mentioned somewhere in the "normal" documentation as it obviously increases the possibilities a lot! Have a good time.

One additional item if I may:

 

once I use the function for a field, I cannot edit it any more. See the attached screenshot. Also only my second function works. For Email Addresses my approach seems not to work. I also tried it without the ? mark.

 

Last Problem. If I dont put it inside " " - then it is not detected as function, but when I do it, the " " signs are part of the output which they should not. I tried both "()" and "{}" as outer brackets of the whole call.

 

 

screenshot

ok I found out what is the cause for one of the problems. Using "@" does not work if there is not at least one other character before it, so using space, it works. It is still not editable though.

 

Tried to access the mail address: @first(item()?['emailAddresses'])?['address'] but that does not seem to work like that. The mail address is the address property in the first item of the emailAddresses array. 

Hi @unimatrix27,

 

Yes, it is not editable if we specify Workflow Definition Language in the Actions, with WDL used, the formula is hard-coded within workflow, we need to delete the related action and add it again to edit.

For formula used within the Actions (Like Trigger, Actions based on Connections) added in Microsoft Flow, we use the format below:

"@{formula}"

But if we use Compose Action to phase the dynamic content, we use the format below in the Compose Input:

"@formula"

Using Compose would give us the results without the double quote.

Apologize for that the Contacts saved would have the double quotes, please take a try with the action below:

1. Open the corresponding flow and click Edit,

2. Under hte Apply to each, delete the Google Create a Contact action, add then add two Compose Action, first one rename to Address, and second rename to Phone, with the corresponding formula specified (see image), then add the Contact, use the corresponding Compose output with the Email Address and the Phone box under the Google Contact Action:

18.PNG

This way the Contact would be saved without quotes.(Red underline is newly created, highlighted is older).

Please note that the contacts has a filter under the filter query:

@greater(item()?['DateTimeCreated'], adddays(utcnow(),-1))

Which means if the contacts created time is one day older, it won't be listed as an available data with the filter query Action.

 

19.PNG

If you have any further questions, please feel free to post back.

Regards

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ok thanks for the comprehensive answer. I can confirm that now this fully works. Having that sorted out, I can say, that I beleive Microsoft Flow is a valuable addition to Office365 in the direction of citizen integration, but there is still a way to go to catch up with the competing systems like Zapier and others. With more and more (business)-end users using cloud services both in their business world as well as their personal world, I see a drastically increasing demand for solutions in that area, which are on one side useable by non-techies just by "clicking something together" and at the same time enable power-users to use all the potential with things like WDL, etc. Just to stay at the example of my flow here with the google contact creation, what I actually really would like to have is a way to sync the contacts, not just create them, but for that to work its necessary to read the contacts, and possibly do a element-by-element comparision, etc.

 

In any case, thanks for your support.

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.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (3,376)