Skip to main content

Notifications

Power Apps - Power Apps Pro Dev & ISV
Answered

Using check boxes in a gallery to write info back to sharepoint list

(0) ShareShare
ReportReport
Posted on by 33

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);
  • WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Using check boxes in a gallery to write info back to sharepoint list
    You have specified three parameters in the trigger (so that is what it should be expecting)
     
     
    Disconnect and reconnect the Flow and see if that works.
  • jpdamd Profile Picture
    jpdamd 33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Thanks so much Warren your unreal!

    Emails and attachments are working now. Really sorry but if I could pick your brain about one last issue. Its with an approval from within the App. I've set up a power automate flow that looks like the below. I'm trying this code but it is saying invalid number of arguments received 3, expected 1.
     
    Goal of the flow is to have someone select a element and level within the dropdowns then when they hit submit it runs the flow, goes for approval and only updates the sharepoint list after the approval has been granted.

    Do you take tips or donations mate, you've helped out so much with this, have no clue how I would have got it done without you.


    Set(flowResponse,
        ChifleyApprovalFlow.Run(
            SelectedDocket.ID,                      // Pass the selected item ID
            Dropdown1.Selected.Value,               // Pass the selected ELEMENT
            Dropdown3.Selected.Value                // Pass the selected LEVEL
        )
    );
     
    // Check if the flow response indicates approval was granted
    If(
        flowResponse.approvalStatus = "Approved",
       
        // If approved, patch the changes to SharePoint
        Patch(
            'Delivery Docket Register',
            LookUp('Delivery Docket Register', ID = SelectedDocket.ID),
            {
                ELEMENT: Dropdown1.Selected.Value,
                LEVEL: Dropdown3.Selected.Value
            }
        );
        Refresh('Delivery Docket Register');
        Notify("Changes successfully submitted.", NotificationType.Success),


  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Using check boxes in a gallery to write info back to sharepoint list
    If the user is simply attaching the file/s in the attachment control and you want it emailed with the current record, then forget about the Variable (just leave the Items blank) and go right back to what I posted at the start of this part of the process
    Office365Outlook.SendEmailV2(
       "myemail@gmail.com",
       "Missing Items for Sch: " & SELECTEDSCHEDULE.'Sch + Rev',
       "The following items were marked as missing for Docket <b>" & SELECTEDSCHEDULE.'Sch + Rev' & "</b>:<br><br>" &
       Concat(  
          _MissingItems,
          "<b>Item Code</b>: " & 'Item Code' & " - Qty Ordered: " & 'Qty Ordered' & " - Qty Missing: " & 'QTY MISSING' & "<br><br>"  
       ) &
       "<br><b>Comments:</b> " & TextInputCanvas1.Value,
       {
          Cc: "james@clutchtrack.com",
          Importance: "High",
          Attachments: 
          RenameColumns(
             AttachmentControlemail.Attachments,
             Value, 
             ContentBytes
          )
       }
    );
    Notify(
       "Email sent for missing items", 
       NotificationType.Information
    )
     
  • jpdamd Profile Picture
    jpdamd 33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Thanks Warren. So the attachment is just being added to that document control by the user. Do I need to do something that assigns it to the list item, at the minute it just seems to sit in the document control, maybe thats why there is nothing being picked up.

  • Suggested answer
    SaiRT14 Profile Picture
    SaiRT14 1,926 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Set(ErrorMessage, "");
    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),
        // Proceed if SELECTEDSCHEDULE is set
        ClearCollect(Selected_Items, Filter(Gallery2.AllItems, Checkbox.Checked));
        If(
            CountRows(Selected_Items) = 0,
            Set(ErrorMessage, "No items selected.");
            Notify("Error: No items selected", NotificationType.Error),
            Notify("Selected items collected: " & CountRows(Selected_Items), NotificationType.Information);
            
            // Update Docket Items
            Patch(
                'Docket Items',
                ForAll(Selected_Items, { ID: ID, DELIVERED: "YES" })
            );
            Notify("Docket Items updated successfully.", NotificationType.Information);
            
            // Check if all items are delivered
            With(
                {
                    _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: { Value: If(_AllItemsDelivered, "YES", "PART RECEIVED") },
                            'DATE DELIVERED': If(_AllItemsDelivered, Today(), Blank())
                        }
                    )
                );
                If(
                    IsError(updateResult),
                    Set(ErrorMessage, "Error updating Delivery Docket Register: " & Text(Error(updateResult)) & ";");
                    Notify("Error updating Delivery Docket Register", NotificationType.Error),
                    Notify("Delivery Docket Register updated - " & If(_AllItemsDelivered, "Full Delivery", "Partial Delivery"), NotificationType.Information)
                );
                
                // Send email if not all items delivered
                If(
                    !_AllItemsDelivered,
                    Set(
                        emailResult,
                        Office365Outlook.SendEmailV2(
                            "samplesupplier@gmail.com",
                            "Partial Delivery Notification",
                            "The following items were not delivered for Docket " & SELECTEDSCHEDULE.'Sch + Rev' & ": " &
                            Concat(
                                Filter(Gallery2.AllItems, !Checkbox.Checked),
                                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 gallery and checkboxes
            Reset(Gallery2);
            Notify("Checkboxes reset.", NotificationType.Information);
            
            // Display success or error message
            If(
                !IsBlank(ErrorMessage),
                Notify("Errors occurred: " & ErrorMessage, NotificationType.Error),
                Notify("Process completed successfully.", NotificationType.Success)
            )
        )
    )
     
  • WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Assuming the attachment/s are on the record in 'Docket Items' selected in the gallery, then that structure works perfectly here using a list with attachments. I notice also an error on your Attachment control (though I am using the collection to attach to the email), so there may be a clue there. Your collection should look something like this - I am then using the Value and DisplayName fields to send ContentBytes and Name to the email attachments.
     
  • jpdamd Profile Picture
    jpdamd 33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    I've set the code for my attachment control to colAttach

    Onvisible for the screen is set 
    ClearCollect(
       colAttach,
       ShowColumns(
          Defaults('Docket Items'),
          Attachments
       )
    );
    Clear(colAttach);
    UpdateContext({varReset: false});
    UpdateContext({varReset: true});

     
    I've added the collect section to my button that marks the item as Missing.

    I've tried attaching the document before pressing the button and after. The email is sending now but still without any attachment.
     
    If(
        ThisItem.DELIVERED = "MISSING",
        Patch(
            'Docket Items',
            ThisItem,
            {
                DELIVERED: "",
                'QTY MISSING': Blank()  // Clears the QTY MISSING field
            }
        ),
        Patch(
            'Docket Items',
            ThisItem,
            {
                DELIVERED: "MISSING",
                'QTY MISSING': varMissingQty  // Updates the QTY MISSING field with the value entered by the user
            }
        )
    );
    Collect(
        colAttach,
        ThisItem.Attachments
    );
    Notify(
        "Status updated to " & ThisItem.DELIVERED,
        NotificationType.Information
    );
     
     
  • WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Using check boxes in a gallery to write info back to sharepoint list
    The model works here, so I am not sure what you have done different. If you use the attachment control as it is intended (user simply uploads the attachment), then your original code will work, so you do not need a Variable.
  • jpdamd Profile Picture
    jpdamd 33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Thanks Warren but I think I might have explained it wrong.

    With the attachment control I want the user to have the option to upload an image before clicking the button the sends the email.

    The attachment will sit on the Delivery Docket Register Item (The overall docket) not the individual gallery item which are the line items from the Delivery Docket ('Docket Items' is the name of that sharepoint list). The Delivery Docket Register item (SELECTEDSCHEDULE) will have an attachment which is a PDF that triggers the AI Builder flow to extract the information and populate the docket items list. This doesn't really need to go in the email its more the upload that the user would do within the attachment control but if both get attached then thats fine too.

    I've also taken away the checkboxes and replaced them with buttons in the gallery that mark the Docket Item as missing which is building the collection and working well for everything. These attachments just don't seem to want to work :/

    The solution you gave is returning the error below





    Apologies, this is the first app i've tried building so really appreciate your help and patience with this


  • WarrenBelz Profile Picture
    WarrenBelz 145,422 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Please see my latest post - Attachments are designed to use Attachment controls on Forms and any other use is a workaround (more likely a "hack") - I got the model I posted working - there are a couple of other things that technically possibly should work, but simply do not.

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,422

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,711

Leaderboard