cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bf
Frequent Visitor

Using If function while building an array

I'm trying to process some data from a webhook where one object is an array. The results populate a word document template.

Amongst other strings that work fine, the array is called "selected_items" and The array fields are "heading", "description" and "quantity"

Sometimes the description is empty and the quantity is 0

 

What I want to achieve is that when the description is empty, the value is set to the same as the heading value and the heading value is blank

I also want the quantity field to be blank when it is zero.

 

I tried using the if function when appending the data to a variable, however when I open the function those fields from the array are no longer visible. Ideally I'd like to have something like: if heading == "", "title", "heading"

or: if quantity == 0, '', quantity

 

Hope you can help

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-yujincui-msft
Community Support
Community Support

Hi  @bf , 

 

Sometimes, we can use expressions to get invisible fields in dynamic content.

I have made a test for your reference.

item()?['Title']
item()?['selected_items/heading']
if(empty(item()?['selected_items/description']),item()?['selected_items/heading'],item()?['selected_items/description'])
if(equals(item()?['selected_items/quantity'],'0'),'',item()?['selected_items/quantity'])
item()?['ID']
vyujincuimsft_0-1651046245368.pngvyujincuimsft_1-1651046264487.png

vyujincuimsft_2-1651046367107.png

 

Result Screenshot:

vyujincuimsft_3-1651045520397.png

 

Best Regards,

Charlie Choi

View solution in original post

bf
Frequent Visitor

After further playing around I have solved it.

 

The expressions need to be, respectively:

if(empty(items('Build_Line_Items')?['description']),'',items('Build_Line_Items')?['heading'])
if(empty(items('Build_Line_Items')?['description']),items('Build_Line_Items')?['heading'],items('Build_Line_Items')?['description'])
if(equals(items('Build_Line_Items')?['quantity'],'0'),'',items('Build_Line_Items')?['quantity'])

 

 

View solution in original post

3 REPLIES 3
v-yujincui-msft
Community Support
Community Support

Hi  @bf , 

 

Sometimes, we can use expressions to get invisible fields in dynamic content.

I have made a test for your reference.

item()?['Title']
item()?['selected_items/heading']
if(empty(item()?['selected_items/description']),item()?['selected_items/heading'],item()?['selected_items/description'])
if(equals(item()?['selected_items/quantity'],'0'),'',item()?['selected_items/quantity'])
item()?['ID']
vyujincuimsft_0-1651046245368.pngvyujincuimsft_1-1651046264487.png

vyujincuimsft_2-1651046367107.png

 

Result Screenshot:

vyujincuimsft_3-1651045520397.png

 

Best Regards,

Charlie Choi

bf
Frequent Visitor

Thanks for the reply and sorry for the delayed response. It is good to know that these things can be hidden. The issue I am having is that the array I need to work with is coming from a webhook and does not include an ID or title. When I try your code above I just get "null" for the fields.

 

Here is a snip from my flow. the selected_items array in the Build Line Items object is straight from the http request received

 

bf_0-1655858102747.png

 

Any way I can do this without such title and id fields?

bf
Frequent Visitor

After further playing around I have solved it.

 

The expressions need to be, respectively:

if(empty(items('Build_Line_Items')?['description']),'',items('Build_Line_Items')?['heading'])
if(empty(items('Build_Line_Items')?['description']),items('Build_Line_Items')?['heading'],items('Build_Line_Items')?['description'])
if(equals(items('Build_Line_Items')?['quantity'],'0'),'',items('Build_Line_Items')?['quantity'])

 

 

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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (1,845)