cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Making objects in an array entirely conditional

So a record is created in Dynamics 365 which connects to a web API for a web app we use that I put together a custom connector for.

There are a number of custom fields that I am trying to map. The issue I'm running into now is if the field is blank in CRM, it is submitting that with nothing to the other web API which is expecting. This causes the Flow to fail, so trying to figure out how to make the entire custom_field conditional. This is what I am looking at:

custom_fields.PNG

So, for example, if the Project Kickoff is blank, it still tries to submit:

"custom_fields": [
  {
    "custom_field_id": "434755",
    "value": ""
  },
  {
    "custom_field_id": "442485",
    "value": "Test User"
  }
]

This triggers an error.

How can I make that entire object in the array conditional?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Helper III
Helper III

Re: Making objects in an array entirely conditional

Ok, got this working. There are likely many ways of doing this, but this is the way I did it.

Untitled2.png

As far as the if statement in the "Set variable" when true, it looks like the following. I was trying to avoid having 25 conditions eating up a ton of real estate on the screen, so elected to do this which is probably as equally hard to read... didn't seem to be any good way to do this.

if(equals(items('Iterate_Through_Field_List_Values'),'481385'),triggerBody()?['tcc_mlaccount'],if(equals(items('Iterate_Through_Field_List_Values'),'442485'),triggerBody()?['tcc_mlcontact'],''))

EDIT: 

Here are some better pictures:

1.PNG2.PNG3.PNG

View solution in original post

5 REPLIES 5
Highlighted
Community Support
Community Support

Re: Making objects in an array entirely conditional

Hi @ishraqiyun77 ,

 

You could initialize an array variable to store custom_fields value.

Configure append to array variable action to append non-null custom_field_id to this array.

Finally, click here and populate array variable to this field.

custom_fields.PNG

Hope it makes sense.

 

Best Regards,

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

Re: Making objects in an array entirely conditional

Hi @v-bacao-msft,

I think I follow somewhat.

I'd pick the Append to Array variable action, set the name, and then add an expression that if a given Dynamics 365 field is populated (i.e., custom_field_value), add the custom_field_id to the array, correct?

I guess I'm not seeing how I'd create an array of objects though, which is what I'd need to do in this case.

Seems like I'd need to something like one of these properties, but I don't quite get what I'd be passing in for the first paramter ("object").

custom_field.PNG

Highlighted
Helper III
Helper III

Re: Making objects in an array entirely conditional

To add to this, I'm trying to start small. I'm messing with the compose action and then passing that into the connector for the custom_field array. What I have below works, and from that I can figure out how to pass in array and all. What I'm not figuring out is how to make this entire object conditional. I can pass an empty array to the API, but I can't return empty objects.

Capture.PNG

One thought was to initialize an array with all of the custom_field_id, iterating through it, and creating a new object with each iteration... but apparently that isn't possible:

Capture.PNG

Highlighted
Helper III
Helper III

Re: Making objects in an array entirely conditional

Making progress, but for some reason this always evaluates to false.

Untitled.png

Highlighted
Helper III
Helper III

Re: Making objects in an array entirely conditional

Ok, got this working. There are likely many ways of doing this, but this is the way I did it.

Untitled2.png

As far as the if statement in the "Set variable" when true, it looks like the following. I was trying to avoid having 25 conditions eating up a ton of real estate on the screen, so elected to do this which is probably as equally hard to read... didn't seem to be any good way to do this.

if(equals(items('Iterate_Through_Field_List_Values'),'481385'),triggerBody()?['tcc_mlaccount'],if(equals(items('Iterate_Through_Field_List_Values'),'442485'),triggerBody()?['tcc_mlcontact'],''))

EDIT: 

Here are some better pictures:

1.PNG2.PNG3.PNG

View solution in original post

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (8,803)