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
yashag2255
Dual Super User II
Dual Super User II

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.

yashag2255
Dual Super User II
Dual Super User II

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
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Users online (73,967)