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.

Report
All responses (
Answers (