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

Update specific Item with dynamic position in Array according to Inputdata

Hi, 

 

is there a way to Update the following array:

 

[
  {
    "Name": "Max Muscle",
    "Email": "maxmuscle@muster.com",
    "Course 1": "x",
    "Course 2": "o"


  },
  {
    "Name": "Michael Johnson",
    "Email": "mj@google.com",
     "Course 1": "o",
    "Course 2": "o"
  

  },
  {
    "Name": "Dummy Dummy",
    "Email": "dummy@dummy.com",
     "Course 1": "x",
    "Course 2": "x"

  }
]

with this Input-data:

[
  {
     "version": "1.17",
    "userEmail": "knightright@sin.com",
    "userName": null,
    "sendDate": "2019-06-28T21:15:47.6208279Z",
    "receivedDate": "2019-06-28T21:15:48.0330384Z",

    "title": "Form1",
    "data": {
      "DataRecord": {
        "Name": "Michael Johnson",
		"Email": "mj@google.com",
		
      },
		"Username": "Michael Johnson",
		"Course 1": "o",
		"Course 2": "o""
      }
  }
]

so the specific array where the "Name" has the value "Michael Johnson" needs to be updated according to the inputdata (marked in pink). The thing is: It cannot be done by using [1] index, because the position of the item in the array is dynamic and can be also the third or first position.

 

Is there any way to solve this problem?

Thank you for your help!


Regards Julian

4 REPLIES 4

Hi @Julian1 

 

From what I understand you want to find an element in an array and update another array based on that? Plase have a look at the screenshot below:arrays.png

 

Here I am looking for the name and email in the array and if that is a match, i am extracting the stuff and populating another array. 

 

Expression used in the condition:

 

items('Apply_to_each')['Name']
items('Apply_to_each')['mj@google.com']

Expression used in append array variable:

items('Apply_to_each')['Name']
items('Apply_to_each')['Course 1']
items('Apply_to_each')['Course 2']

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Thank for your help. Sadly its the other way around. I need the second Code ("InputData") as the Inputdata for the first array... I need a function so search in the first array for the right position.

Hey @Julian1 

 

You could just flip that around then. All you have to do is access the field from the data source and then look for that in the target and update the rest (just as I showed in the flow)

 

Please let us know if you face any issues with that. 

 

Hope this helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

v-bacao-msft
Community Support
Community Support

Hi @Julian1 ,

 

Please try to use the following method.

  • Use Parse JSON action to parse the input data and the array separately.
  • Determines whether UserName in the Input-data is equal to Name in the array.
  • If they are equal, the specified property is updated. If they are not equal, the element is directly appended to the array.

 

You could download the attachment I uploaded and import it to configure Flow.

Note that this method currently works for input-data with only one element in this array.

 

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.

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,601)