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 / Submitted & Retrieving...
Power Apps
Unanswered

Submitted & Retrieving SPL Collections with Conditions

(0) ShareShare
ReportReport
Posted on by 77

Hello brave soul,
I'm struggling with the proper method of Saving, Loading a collection to a SharePoint List.  I have researched the subject extensively, the below is the best method I'm able to deploy.  It's hectic, causing fallout that's hard to manage.  I'm seeking notes on how to correct this, or a better approach, with notes of limitations of the system.

 

This expense app requires Users creating Expense Reports for themselves, creating reports for other employees, and also editing reports for themselves, and other employees.

Key Variables:

userFilter = Current User (saving as MailNickname criteria)
isReportSubmitted = indicating status of Report, being "No", "Draft", and "Yes" ("No" and "Draft" may be redundent).

Datasource:
"Expenses" - SPL that everything is saved to, loaded from.

Main Collection
"expReport" - Main Collection used in App to build report.


Auto Loading on AppStart
"colExpensed" = load unsubmitted report items from SPL, targeting ID (Loading on AppStart, with isReportSubmitted ="No")

;ClearCollect(
 colExpensed,
 Filter(ShowColumns(
 Expenses,
 "Title",
 "Item",
 "Cost",
	 "ID",
	 "userFilter",
	 "isReportSubmitted"
		),
 userFilter=User().FullName && isReportSubmitted = "No"
 ) 
)

//Then appends to expReport
;If(CountRows(colExpensed)>0,
ForAll(
 colExpensed,
 Patch(
 expReport,
 Defaults(expReport),
 {
		Title: Title,
		ItemNo: ItemNo,
		Cost: Cost,
		userFilter: userFilter,
		ID: Value(ID),
		isReportSubmitted: "No"
	 }
 )
))


User Selected Load - After the AppStart is completed, on HomeScreen, there is an option for User to edit a previously submitted or Draft Report:

ClearCollect(
 colExpenseEdit,
 Filter(
 ShowColumns(
 Expenses,
 "Title",
 "Item",
 "Cost",
	 "ID",
	 "userFilter",
	 "isReportSubmitted"
 ),
 isReportSubmitted = "Yes" && Title = ddExpenseEdit.SelectedText.Result || isReportSubmitted = "Draft" && Title = ddExpenseEdit.SelectedText.Result
 ) 
)

;ForAll(
 colExpenseEdit,
 Patch(
 expReport,
 Defaults(expReport),
 {
 Title: ddExpenseEdit.SelectedText.Result &"R1",
 ItemNo: ItemNo,
	 Cost: Cost,
	 ID: ID,
 userFilter: userFilter,
 isReportSubmitted: ""
 }
 )
) 


Saving from Button

 

"expReportEdit" = saving loaded SPL report items back to isReportSubmitted: SPL "Draft" status (SPL ID >0)
"expReportNew" = saving new report items to SPL with a isReportSubmitted: "Draft" status (ID = 0, not yet sent to SPL)

ClearCollect(
 expReportEdit,
 Filter(
 ShowColumns(
 expReport,
 "Title",
 "Item",
 "Cost",
	 "ID",
	 "userFilter",
	 "isReportSubmitted"
 ),
 ID > 0 
 )
)
;

ClearCollect(
 expReportNew,
 Filter(
 ShowColumns(
 expReport,
 "Title",
 "Item",
 "Cost",
	 "ID",
	 "userFilter",
	 "isReportSubmitted"
 ),
 ID = 0
 )
)
;ForAll(
 expReportNew,
 Patch(
 Expenses,
 {
		Title: Title & ".d",
		ItemNo: ItemNo,
		Cost: Cost,
		userFilter: userFilter,
		ID: Value(ID),
		userFilter: userFilter,
		isReportSubmitted: "Draft"
 } 
 )
)
 ;If(!IsEmpty(expReportEdit),
 ForAll(
 expReportEdit,
 Patch(
 Expenses, 
 {ID: (ID)},
 {
			Title: Title & ".d",
			ItemNo: ItemNo,
			Cost: Cost,
			userFilter: userFilter,
			ID: Value(ID),
			userFilter: userFilter,
			isReportSubmitted: "Draft"
		} 
 )
)
)

Saving upon Exit
When user exits and the main collection has items Unsubmitted, runs the same collections expReportNew and expReportEdit and saves isReportSubmitted= "No".

ClearCollect(
 expReportEdit,
 Filter(
 ShowColumns(
 expReport,
 "Title",
 "Item",
 "Cost",
	 "ID",
	 "userFilter",
	 "isReportSubmitted"
 ),
 ID > 0 
 )
)
;

ClearCollect(
 expReportNew,
 Filter(
 ShowColumns(
 expReport,
 "Title",
 "Item",
 "Cost",
	 "ID",
	 "userFilter",
	 "isReportSubmitted"
 ),
 ID = 0
 )
)
;ForAll(
 expReportNew,
 Patch(
 Expenses,
 {
		Title: Title & ".d",
		ItemNo: ItemNo,
		Cost: Cost,
		userFilter: userFilter,
		ID: Value(ID),
		userFilter: userFilter,
		isReportSubmitted: "No"
 } 
 )
)
 ;If(!IsEmpty(expReportEdit),
 ForAll(
 expReportEdit,
 Patch(
 Expenses, 
 {ID: (ID)},
 {
		Title: Title & ".d",
		ItemNo: ItemNo,
		Cost: Cost,
		userFilter: userFilter,
		ID: Value(ID),
		userFilter: userFilter,
		isReportSubmitted: "No"
	} 
 )
)
)


Sending as Final
Both collections run a ClearCollect from main collection
"expReportEdit" = saving loaded SPL report items back to isReportSubmitted: SPL "Yes" status (SPL ID >0)
"expReportNew" = saving new report items to SPL with a isReportSubmitted: "Yes" status (ID = 0, not yet sent to SPL)

 

 

// The following is to Submit report to as "isReportSubmitted: Yes", on Screen titled "Export Screen"
(Note: OnVisible for "Export Screen" performs another ClearCollect for expReportEdit and expReportNew on the expReport Collection)
; 
ForAll(
 expReportEdit,
 Patch(
 Expenses, 
 {ID: (ID)},
 {
 Title: Title,
	 ItemNo: ItemNo,			
	 Cost: Cost,
 userFilter: userFilter,
 isReportSubmitted: "Yes"
 } 
 )
);
 
ForAll(
 expReportNew,
 Patch(
 Expenses, 
 {
 Title: Title,
 ItemNo: ItemNo,
	 Cost: Cost,
 userFilter: userFilter,
 isReportSubmitted: "Yes"
 } 
 )
)


The above code snippets are provided to show logic used, if syntax is slightly off don't worry - that's not the problem (copied/pasted/redacted from actual source). 

Please feel free to rip this apart, call me dumb,  paste links (I'll comment if i've investigated or not), or simply confirm what I'm trying to attempt isn't possible.  

 

Please, I need this suffering to end.  

 

 

 

Categories:
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @cofordpa 

     

    Instead of using  ddExpenseEdit.SelectedText.Result in your formulas, can you try to modify this to:  ddExpenseEdit.Selected.Result.
     
    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!

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard