web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Parse nested tables fr...
Power Apps
Answered

Parse nested tables from JSON

(0) ShareShare
ReportReport
Posted on by 59

I am trying to store approval data within an approval workflow.

The original request contains two tables of bookings (plus and minus bookings). Each record in each table has six values (account number, receiving dep, amount...). Each request can contain one or multiple bookings.

Now when the first of four approvers receive the request, he or she can adjust each record in each table. They can alter existing records, add new ones, or delete existing ones.  I must store each change to each record in each step of the approval flow. So, I created three new collections (change, add, delete). In "change" I only save the booking id, the changed field, the old and the new value. In both "add" and "delete" I save the entire record.

Since I save the approval in a JSON object anyway, my idea was to attach the content of these three collections to the actual approval. And that works perfectly.

Collect(
 col_Approval,
 {
 Step: rec_ThisApproval.step,
 Approver: User().Email,
 Timestamp: Now()
 changes: If( !IsEmpty( col_Changes), col_Changes),
 deletions: If( !IsEmpty( col_Delations), col_Deletions),
 additions: If( !IsEmpty( col_Additions), col_Additions)
 }
);

If  I create a JSON object from this I get something like

[
	{
		"additions": [
			{
				"account": "19082",
				"amount": 200.98,
				"index": 4,
				"type": outgoing
			}
		],
		"approver": jack.liberty@mycompany.de,
		"changes": [
			{
				"field": "amount",
				"index": 2,
				"new_value": 200,
				"old_value": 220
			},
			{
				"field": "account",
				"index": 1,
				"new_value": "12009",
				"old_value": "12090"
			}
		],
		"deletions": null,
		"step": 1,
		"timestamp": "19/04/2023 17:07"
	}
]

 

When I parse the object I can parse the nested tables into my new collection:

ClearCollect(
	col_AllApprovals,
	ForAll(
		Table(
			ParseJSON(
				rec_thisRecordGbl.Approvals)),
				{
					step: Text( ThisRecord.Value.step),
					...
					additions: Table( ThisRecord.Value.additions)
					changes: Table( ThisRecord.Value.changes)
					deletions: Table( ThisRecord.Value.deletions)
				}
	)
);

 

But now I'm stuck. I feel like I was more than half-way there, but I don't know how to parse the values out of "col_AllApprovals.additions". If I look at the collection it shows a table icon for this column. When I click on the item the table is empty (obviously). There is only a "?" in the column "Value" of this table.

I tried something along the lines of

ForAll(
	Table(
		ParseJSON(
			col_AllApprovals.changes))
			{
			...
			}
);

Which results in an error since ParseJSON considers the col_AllApprovals.changes not as text but as table. Converting the nested tables to text while parsing the approval object also won't work.

 

Do you have any ideas what I can do from here?

 

(Fallback would be to save the change-, addition-, and deletion-object in separate objects in the SharePoint list. But I think we can do better than that).

 

Categories:
I have the same question (0)
  • Reinerknudsen87 Profile Picture
    59 on at

    After a lot of trying around I finally made it here. This code doesn't give me any errors. BUT it doesn't provide any values from the original object either. 

    ClearCollect(
    	col_AllApprovals,
    	ForAll(
    		Table(
    			ParseJSON(
    				rec_thisRecordGbl.Approvals)),
    				{
    					step: Text( ThisRecord.Value.step),
    					...
    					additions: 
    					ForAll(
    						Table( 
    							ParseJSON( rec_thisRecordGbl.Approvals).additions) As DATA,
    							{
    							account: Text( DATA.Value.account),
    							amount: Value( DATA.Value.amount),
    							index: Value( DATA.Value.index),
    							type: Text( DATA.Value.type)
    							}
    						)
    				}
    	)
    );

    I can feel it must be somewhere around here. It seems like it can address the additions object within the approval object but it doesn't get any values out.

    Help!

  • Verified answer
    ShantanuP Profile Picture
    Microsoft Employee on at

    Following should work. 

     

    ClearCollect(
    	col_AllApprovals,
    	ForAll(
    		Table(
    			ParseJSON(
    				rec_thisRecordGbl.Approvals)),
    				{
    					step: Text( ThisRecord.step),
    					...
    					additions: ForAll(ThisRecord.additions, {account: Text(ThisRecord.account)})
    				}
    	)
    );

     

  • Reinerknudsen87 Profile Picture
    59 on at

    Brilliant! THAT works!

    All I had to add was the "Value" in

    additions: ForAll(ThisRecord.Value.additions, {account: Text(ThisRecord.account)})

     Thank you ever so much! You really made my day!

  • pankajpatidar Profile Picture
    4 on at

    This has saved me so much time. Thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 463

#2
WarrenBelz Profile Picture

WarrenBelz 364 Most Valuable Professional

#3
11manish Profile Picture

11manish 275

Last 30 days Overall leaderboard