cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Community Champion
Community Champion

Looking for expression to join arrays.

I thought I saw this before, but after an hour of looking, I cant find it.  Simply put.  I have two arrays, with a common DocumentID.  I just need to JOIN them goether ON DocumentID (using SQL lingo)

 

Array1:

 

 

[
  {
    "DocumentID": 1265,
    "PartNumber": "510009",
    "Rev": "1",
    "Description": "KBOV HANDLE BRACKET ASSEMBLY"
  },
  {
    "DocumentID": 2338,
    "PartNumber": "KBV8-N-FW",
    "Rev": "0",
    "Description": "KBV8-N-FW GENERAL ARRANGEMENT & BOM"
  },
  {
    "DocumentID": 5522,
    "PartNumber": "213155",
    "Rev": "0",
    "Description": ".125 X .50 DOWEL PIN CS"
  }
 
]

 

 

 

Array2:

 

 

[
  {
    "DocumentID": 1265,
    "Comment": "."
  },
  {
    "DocumentID": 2338,
    "Comment": "Exploded view still WIP."
  },
  {
    "DocumentID": 5522,
    "Comment": "."
  }

]

 

 

 

This is what I want:

 

 

 

[
  {
    "DocumentID": 1265,
    "PartNumber": "510009",
    "Rev": "1",
    "Description": "KBOV HANDLE BRACKET ASSEMBLY",
    "Comment": "."
  },
  {
    "DocumentID": 2338,
    "PartNumber": "KBV8-N-FW",
    "Rev": "0",
    "Description": "KBV8-N-FW GENERAL ARRANGEMENT & BOM",
    "Comment": "Exploded view still WIP."
  },
  {
    "DocumentID": 5522,
    "PartNumber": "213155",
    "Rev": "0",
    "Description": ".125 X .50 DOWEL PIN CS",
    "Comment": "."
  }
 
]

 

 

 

I'm sure there is a simple expression for this.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @martinav 

 

I am not sure if you have already solved your issue but i find this interesting and thought of  spending some time on it. i finally able to make it work (dont think its a best solution and i may need to work on improving it) but its working.

i uploaded working flow at github: 

https://github.com/DeepakS22/DPowerAutomate/blob/master/MergeJSON_20200327174700.zip

 

Have a look and let me know if that helps.

 

Regards,

 

 

View solution in original post

15 REPLIES 15

@martinav - Have you tried using the "Append to an Array variable"? Here is a video that covers this: https://www.youtube.com/watch?v=VAfwiN-vARQ

@PowerBack19 ,

 

Append adds records.  It does not add items, or "columns" depending on data source.  If you see my data examples, its merging or joining records keyed on DocumentID.  Again, terms depending on the system you are familiar with, SP, SQL, etc.

martinav
Community Champion
Community Champion

I could get there if there is a way to use an expression to get the current item() from these two select functions.  I could combine together.  Of course none of the attempts to write the expression work.

 

image.png

 

Results:

 

image.png

martinav
Community Champion
Community Champion

Ive wasted an entire day on this.  This is one of those times I loathe this system.  This is so forking simple.  Has to be a way to do it.

martinav
Community Champion
Community Champion

Cant go back to the filter array either.  This is absurd.

 

image.png

@martinav 

WDL limitations are usually frustrating.

I have managed to join elements from two different arrays (lets call them 'myInput1Array' and 'myInput2Array') when both elements shared a common property value, but it is very time consuming both on the design and on the performance.

 

So, you need to initialize a third array variable, let's call it 'myOutputArray', leave it empty for the moment.

Now, you use an Apply to each and assign as its input 'myInput1Array'

Inside the Apply to Each, you add a Filter Array and assign as its input 'myInput2Array', try to match common property value from current Apply to each iteration. Now you make sure a single match, if so, Append to array variable, name 'myOutputArray', value:

setProperty(setProperty(setProperty(json('{}'),'Property1FromArray1Name','Value'),'CommoProperty','Value'),Property1FromArray2Name','Value')

So, property values from myInput1Array are obtained from 

items('Apply_to_each')

And, property values from myInput2Array are obtained from

first(body('Filter_array'))

As I mentioned, very inneficient but saved my day

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



martinav
Community Champion
Community Champion

@efialttes ,

 

You have NO idea how much I appreciate the help of others here.  I am working through this solution.  I think of myself as pretty savvy with this type of thing, but I will tell you.  The absolute convolution of how many things work in this system is very troubling.  I am completely dumbfounded on how people come up with solutions like this.  Even with the answer right in front of me, and using the SAME names, etc, it is still very difficult to get everything right to make it work.  I'm still working on it, and will report back when its working.  I need to implement this solution to several flows.

 

Its funny, because to do the exact same thing in powerapps is also a trick. I can get my head around it better, but it took a while to figure out the ForAll() statement.  What is sooo simple in SQL (JOIN statement).  I still have to study what I did on other apps in order to use it again, but I have a solution on that side of the power platform.  I do find it interesting that these tools are designed as "code free", but when it comes down too it, you have to know more different types of code in order to get things to work the way you want.  If you are super simple, you can get out of it, but if you do anything of real depth, then you have to figure out MANY different languages.  ODATA, JSON, and Expressions (flow) just to name a couple.  Doing the same type of thing in PowerApps compared to Flow is an entirely different animal and requires very different knowledge.

 

Sorry, I'm whining a bit.  I'll report on progress.

Hi!

I understand your concerns: PowerApps with its own language, Power Automate too, ODATA... sometimes is a bit frustrating... The dream of zero code is still a dream, even thought Microsoft is putting lots of efforts to help us

Hope your story will have a happy ending... please let us know your progress on your challenge

Thanx!

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hi @martinav 

 

I am not sure if you have already solved your issue but i find this interesting and thought of  spending some time on it. i finally able to make it work (dont think its a best solution and i may need to work on improving it) but its working.

i uploaded working flow at github: 

https://github.com/DeepakS22/DPowerAutomate/blob/master/MergeJSON_20200327174700.zip

 

Have a look and let me know if that helps.

 

Regards,

 

 

View solution in original post

martinav
Community Champion
Community Champion

@DeepakS ,

 

Oh, I most certainly have not resolved my issue.  I thought it would be easy to just make a SQL View, because it is a simplified form of a view I already have.  However, that also is failing, and I have beat on it for several hours.  Side-by side comparison with an existing, and its been expressly perfect, but does not work.  I'm about to bail on this.

 

However, I was surprised by your post.  Of course, I'm confronted once again with an unknown, and unintuitive task... which is how the hello do you import a flow from what you have given.  Especially since I had no idea that you could even export them.  

 

I will try it if this task is not a multi-hour challenge.

 

Any direction on where to go to do this?

 

Thank you.

Hi @martinav 

 

Yes you can export/import. to import my flow just download it as it is and import here is an screen:

Import.png

 

martinav
Community Champion
Community Champion

@DeepakS ,

 

Interesting.  I have never seen that...

 

Trying it...

 

 

martinav
Community Champion
Community Champion

@DeepakS ,

 

Huh, well, lookie there.  That works.  I was dancing around this for hours.  Looks like you saved me a few more.

 

Nice job!

martinav
Community Champion
Community Champion

@DeepakS ,

 

A little update.  I added an additional source to merge.  Thus, I'm merging three arrays together.  Its as "simple" (after getting all of the syntax, language and usage correct) as adding another nested loop.  The disadvantage to this is it took over 2 minutes to run this part of the flow with 6 items in the items being acted upon.  Its only a once a day notification, so PA isnt waiting on it.  But, it is something to keep in mind.  Even two loops deep with 6 items tool over a minute to execute.  This will never be a large number.  I doubt it ever gets over 10 items, but that is something to consider with this method.  Of course, I'm not sure there is another method out there.  This is by far the simplest I saw.  Props to @DeepakS  for this!

 

image.png

Hi @martinav 

 

Yes , even i am not fully like my approach but as of now cant think of any other method, as we are merging two multi filed JSON :(. i can tell its complex in C# too ;).

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (2,006)