Hi, I'm trying to create an app that can help handle deliveries.
I have pulled in information from 2 sharepoint lists 'Delivery Docket Register' & 'Docket Items'. Each delivery docket in my register will have several line items within Docket items where the Sch Number will match up to the Sch + Rev column from my register.
I want to create a way using checkboxes to accept deliveries for the dockets.
The user will then have a button to at the bottom that will mark everything ticked as delivered. This will mark each line in docket items list as delivered then if all items where 'qty delivered' > 0, are marked as delivered then the docket number in delivery docket register gets marked as delivered and the date assigned to date delivered column.
If the user unticks a line item the button should change to part delivered. When they click that it should mark the ticked items as delivered but it should send the unticked line item or items in an email to the supplier with a comment the user can input. The delivery docket register should then show that docket as part delivered until the remain items are received.
I have got to the point where i can nagivate to the Docket Items Check page within my app and see the correct line items from the selected docket but when i try to create the button to write the info back to my sharepoint lists i keep getting errors from the code chatgpt gave me.
See code below
Set(ErrorMessage, ""); // Clear any previous error message
Notify("Button clicked. Starting process...", NotificationType.Information);
// Check if SELECTEDSCHEDULE is set
If(
IsBlank(SELECTEDSCHEDULE),
Set(ErrorMessage, "SELECTEDSCHEDULE is not set.");
Notify("Error: SELECTEDSCHEDULE is not set", NotificationType.Error);
Exit(false)
);
// Collect selected items
ClearCollect(
SelectedItems,
Filter(
Gallery2.AllItems,
Checkbox.Checked = true
)
);
Notify("Selected items collected: " & CountRows(SelectedItems), NotificationType.Information);
// Check if any items are selected
If(
CountRows(SelectedItems) = 0,
Set(ErrorMessage, "No items selected.");
Notify("Error: No items selected", NotificationType.Error);
Exit(false)
);
// Update Docket Items (Assume DELIVERED is a text field here)
ForAll(
SelectedItems,
Patch(
'Docket Items',
LookUp('Docket Items', ID = ThisRecord.ID),
{ DELIVERED: "YES" } // Since it's a text field
)
);
Notify("Docket Items updated successfully.", NotificationType.Information);
// Check if all items are delivered
Set(
AllItemsDelivered,
CountRows(
Filter(
'Docket Items',
'Sch Number' = SELECTEDSCHEDULE.'Sch + Rev' && DELIVERED <> "YES"
)
) = 0
);
Notify("All items delivered: " & If(AllItemsDelivered, "Yes", "No"), NotificationType.Information);
// Update Delivery Docket Register
Set(
updateResult,
Patch(
'Delivery Docket Register',
LookUp('Delivery Docket Register', 'Sch + Rev' = SELECTEDSCHEDULE.'Sch + Rev'),
{
DELIVERED: If(AllItemsDelivered, { Value: "YES" }, { Value: "PART RECEIVED" }), // Assuming DELIVERED in Docket Register is a choice field
'DATE DELIVERED': If(AllItemsDelivered, Today(), Blank())
}
)
);
// Check if the Patch was successful for Delivery Docket Register
If(
IsError(updateResult),
Set(ErrorMessage, "Error updating Delivery Docket Register: " & Text(Error(updateResult)) & ";");
Notify("Error updating Delivery Docket Register", NotificationType.Error),
Notify(If(AllItemsDelivered, "Delivery Docket Register updated - Full Delivery", "Delivery Docket Register updated - Partial Delivery"), NotificationType.Information)
);
// Send email for undelivered items if partial delivery
If(
!AllItemsDelivered,
Set(
emailResult,
Office365Outlook.SendEmailV2(
"samplesupplier@gmail.com",
"Partial Delivery Notification",
Concatenate(
"The following items were not delivered for Docket ",
SELECTEDSCHEDULE.'Sch + Rev',
":",
Char(10),
Concat(
Filter(
Gallery2.AllItems,
Checkbox.Checked = false
),
Concatenate(Title, " - Quantity: ", 'Qty Delivered'),
Char(10)
),
Char(10),
"Comments: ",
TextInputCanvas1.Value
)
)
);
If(
IsError(emailResult),
Set(ErrorMessage, ErrorMessage & "Error sending email: " & Text(Error(emailResult)) & ";");
Notify("Error sending email", NotificationType.Error),
Notify("Email sent for partial delivery", NotificationType.Information)
)
);
// Reset checkboxes
Reset(Gallery2);
Notify("Checkboxes reset.", NotificationType.Information);
// Display any errors
If(
!IsBlank(ErrorMessage),
Notify("Errors occurred: " & ErrorMessage, NotificationType.Error)
);
Notify("Process completed successfully.", NotificationType.Success);