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

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using check boxes in a...
Power Apps
Unanswered

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);
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    152,843 Most Valuable Professional on at
    Using check boxes in a gallery to write info back to sharepoint list
    Hi â€‹â€‹â€‹â€‹â€‹â€‹â€‹jpdamd 
    Firstly is that ChatGPT generated code (as you mentioned) or did you simply get some hints from there ?
    The below is a bit over an "overhaul", meant as structure guidance and is free-typed (so watch commas/brackets etc). A few observations: -
    • You had two Exit commands in there which close the app- is this what you wanted to do ?
    • SelectedItems is a bad name for a Variable as it is a Reserved Word in Power Apps
    • I have tidied up the main Gallery Patch
    • I have made the errors (or not) conditional rather than sequential statements
    Set(
       ErrorMessage, 
       ""
    );
    Notify(
       "Button clicked. Starting process...", 
       NotificationType.Information
    );
    If(
       IsBlank(SELECTEDSCHEDULE),
       Set(
          ErrorMessage, 
          "SELECTEDSCHEDULE is not set."
       );
       Notify(
          "Error: SELECTEDSCHEDULE is not set", 
          NotificationType.Error
       ),
       // Exit(false) This Exits the App !!
       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
          ),
          // Exit(false) This Exits the App !!
          Notify(
             "Selected items collected: " & CountRows(Selected_Items), 
             NotificationType.Information
          );   
          Patch(
             'Docket Items',
             ForAll(
                Selected_Items As _SI
                {
                   ID: _SI.ID,
                   DELIVERED: "YES" 
                }
             )
          );
          Notify(
             "Docket Items updated successfully.", 
             NotificationType.Information
          );
          With(
             {
                _AllItemsDelivered,
                CountRows(
                   Filter(
                      'Docket Items',
                      'Sch Number' = SELECTEDSCHEDULE.'Sch + Rev' && DELIVERED <> "YES"
                   )
                ) = 0
             },
             Notify(
                "All items delivered: " & 
      If(
      _AllItemsDelivered,
      "Yes",
      "No"
      ), NotificationType.Information ); 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 ) ); If( !_AllItemsDelivered, Set( emailResult, Office365Outlook.SendEmailV2( "samplesupplier@gmail.com", "Partial Delivery Notification", "The following items were not delivered for Docket ", SELECTEDSCHEDULE.'Sch + Rev' & ":" & Char(10) & 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(Gallery2); Notify( "Checkboxes reset.", NotificationType.Information ); If( !IsBlank(ErrorMessage), Notify( "Errors occurred: " & ErrorMessage, NotificationType.Error ), Notify( "Process completed successfully.", NotificationType.Success ) ) ) )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee
  • jpdamd Profile Picture
    33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Legend Warren thanks so much for the quick response.

    That really helped. My knowledge is very limited so that was basically a full chatgpt output that I was using. After testing the checkbox for the user experience on an iPad it was a bit clunky. I've decided to change it up to function more like the below.

    Added a button to each gallery item that marks that populates a column in the list as Missing.
    Added a number in put for the user to select the number of items missing, this then gets patched to the Qty Missing column in my list.
    The button then marks everything as delivered or builds the collection of missing items to be emailed. (Having an issue with this. When there are missing items the email doesn't get sent but when there aren't any missing items the email sends with the line below)




    I need to add a Missing Items received button that will then just update the Items that have been marked as missing to Delivered and assign the date but need to get the email working first?
     
    Set(ErrorMessage, "");  // Clear any previous error message
    Notify("Button clicked. Starting process...");
     
    // Collect missing items
    ClearCollect(
        ColMissingItems,
        Filter(
            'Docket Items',
            'Sch Number' = SELECTEDSCHEDULE.'Sch + Rev' && DELIVERED = "MISSING"
        )
    );
     
    // Update non-missing items as Delivered
    ForAll(
        Filter(
            'Docket Items',
            'Sch Number' = SELECTEDSCHEDULE.'Sch + Rev' && DELIVERED <> "MISSING"
        ),
        Patch(
            'Docket Items',
            ThisRecord,
            { DELIVERED: "YES" }
        )
    );
    Notify("Marked all non-missing items as Delivered");
     
    // Count and notify for missing items
    If(
        CountRows(ColMissingItems) > 0,
        Patch(
            'Delivery Docket Register',
            LookUp('Delivery Docket Register', 'Sch + Rev' = SELECTEDSCHEDULE.'Sch + Rev'),
            {
                DELIVERED: { Value: "PART RECEIVED" },  // Assuming DELIVERED is a choice column
                'DATE DELIVERED': Today()
            }
        ),
            Office365Outlook.SendEmailV2(
                "james@insightconsultancy.com.au",
                "Missing Items for Sch: " & SELECTEDSCHEDULE.'Sch + Rev',
                Concatenate(
                    "The following items were marked as missing for Docket ",
                    SELECTEDSCHEDULE.'Sch + Rev', ":",
                    Char(10),  // Optional: Remove if you don't need line breaks
                    Concat(ColMissingItems, ThisRecord.'Item Code' & ThisRecord.'Qty Ordered'),  // Insert the full ColMissingItems collection as text
                    Char(10),  // Optional: Remove if you don't need line breaks
                    "Comments: ",
                    TextInputCanvas1.Value  // Accessing the Text property correctly
                )
            )
        );
     
    // If no missing items, mark entire schedule as Delivered
    If(
        CountRows(ColMissingItems) = 0,
        Patch(
            'Delivery Docket Register',
            LookUp('Delivery Docket Register', 'Sch + Rev' = SELECTEDSCHEDULE.'Sch + Rev'),
            {
                DELIVERED: { Value: "YES" },  // Assuming DELIVERED is a choice column
                'DATE DELIVERED': Today()
            }
        )
    );
    Notify("Process completed");
  • WarrenBelz Profile Picture
    152,843 Most Valuable Professional on at
    Using check boxes in a gallery to write info back to sharepoint list
    Hi jpdamd 
    Now that you have a human writing code with some thought behind it, take some time to understand the changes I have made - some are for code brevity, however the Patch is far more efficient and will run much faster.
    I also suggest that you use Classic controls for the moment - Modern items are not really currently production-ready (they still have some bugs) and have a number of shortcomings in capability compared with Classic items.
    Set(ErrorMessage, "");
    Notify("Button clicked. Starting process...");
    With(
       {
          _MissingItems:
          Filter(
             'Docket Items',
             'Sch Number' = SELECTEDSCHEDULE.'Sch + Rev' && DELIVERED = "MISSING"
          )
       },
       With(
          {_All: CountRows(_MissingItems) = 0},
          If(
             !_All,
             Patch(
                'Docket Items',
                ForAll(
                   _MissingItems As _MI,
                   {
                      ID: _MI.ID,
                      DELIVERED: "YES" 
                   }
                )
             );
             Notify(
                "Marked all non-missing items as Delivered"
                NotificationType.Success
             );
             Office365Outlook.SendEmailV2(
                "james@insightconsultancy.com.au",
                "Missing Items for Sch: " & SELECTEDSCHEDULE.'Sch + Rev',
                "The following items were marked as missing for Docket " & SELECTEDSCHEDULE.'Sch + Rev' & ":<br>" &
                Concat(   
                   _MissingItems, 
                   'Item Code' & ": " & 'Qty Ordered' & "<br>"
                ) & "<br>" & "Comments: " & TextInputCanvas1.Value
             )
          );
          Patch(
             'Delivery Docket Register',
             LookUp(
                'Delivery Docket Register', 
                'Sch + Rev' = SELECTEDSCHEDULE.'Sch + Rev'
             ),
             {
                DELIVERED: 
                {
                   Value: 
                   If(
                      _All,
                      "YES",
                      "PART RECEIVED"
                   )
                },
                'DATE DELIVERED': Today()
             }
          )
       )
    );
    Notify("Process completed");
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee
     
  • jpdamd Profile Picture
    33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    Brilliant thanks again Warren that has helped loads. Everything is working now with the emails and marking off of missing items. Just one thing I cant get working now is to do with attachments.

    I've added an attachment control to my screen and the below code that I got from a youtube tutorial on adding attachments but it continually gives me an error.
    The attachment control is set to the SelectedDocket (Item from my Delivery Docket Register List)
     
    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>" &  // Extra line break
                Concat(  
                   _MissingItems,
                   "<b>Item Code</b>: " & 'Item Code' & " - Qty Ordered: " & 'Qty Ordered' & " - Qty Missing: " & 'QTY MISSING' & "<br><br>"  // Extra line break after each item
                ) &
                "<br><b>Comments:</b> " & TextInputCanvas1.Value,  // Making "Comments" bold
                {
                   Cc: "james@clutchtrack.com",
                   Importance: "High",
                   Attachments: RenameColumns(AttachmentControlemail.Attachments,Value, ContentBytes)}
     
             );
             Notify("Email sent for missing items", NotificationType.Information)
          );


    SelectedDocket.Attachments

  • Verified answer
    WarrenBelz Profile Picture
    152,843 Most Valuable Professional on at
    Using check boxes in a gallery to write info back to sharepoint list
    Hi jpdamd,
    A couple of things - firstly you have referred to _MissingItems, which means the code needs to be run inside a With() statement defining this (either the previous code below the present email or duplicate the statement) - I assume that the extra bracket you have at the end is closing something above.
    However provided that you have at least one attachment inside that control, the attach code is correct (I use it regularly).
    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
    )
    The error is suggesting that there is no content in the control. What is the Items of the control and if in a From, what is the DataSource and Item of the Form ?
    Also, if you want to do it the "long" way, you can use this instead.
    Attachments: 
    ForAll(
       AttachmentControlemail.Attachments As _AC,
       {
          Name: _AC.Name,
          ContentBytes: _AC.Value
       }
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee

     
  • jpdamd Profile Picture
    33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    I'm using SelectedDocket.Attachments as the Item for my AttachmentControlemail

    It is still returning the same error. The SelectedDocket is the variable carried through from my initial screen.

    Select the Docket you want to view


    View then takes the user to the Schedule View screen

    Clicking mark missing items then brings them through to the screen I have the attachment control on.
  • WarrenBelz Profile Picture
    152,843 Most Valuable Professional on at
    Using check boxes in a gallery to write info back to sharepoint list
    How do you set SelectedDockets (code in Text please)?
  • jpdamd Profile Picture
    33 on at
    Using check boxes in a gallery to write info back to sharepoint list
    SelectedDocket gets set on the View button within my Schedule Register View.
    Set
    (SelectedDocket, ThisItem); Navigate('Sch View')

    The Mark Missing Items button on my Schedule View then sets another Variable as this was the only way i could get it to work when moving to the Docket Items screen.
    Set(SELECTEDSCHEDULE, SelectedDocket);
    Navigate('DOCKET ITEMS CHECK', ScreenTransition.None)
     
    I've tried setting the attachment control to SELECTEDSCHEDULE.attachments too but it still returns the Null error when trying to send the email.

    Thanks
  • WarrenBelz Profile Picture
    152,843 Most Valuable Professional on at
    Using check boxes in a gallery to write info back to sharepoint list
    Hi jpdamd
    I think you are heading in the non-optimal direction here with a Variable - I have just done a quick model using a Collection - also you do not need the attachment control (although you can display it if you want), Firstly we are going to set up the collection and reset any controls. You can put this at Screen OnVisible and on a Reset button if you want to do it without exiting the screen
    ClearCollect(
       colAttach,
       ShowColumns(
          Defaults(YourSPList),
          Attachments
       )
    );
    Clear(colAttach);
    UpdateContext({varReset: false});
    UpdateContext({varReset: true});
    On the Reset of both your Checkbox and Attachment control, put
    varReset
    Now OnCheck on the Check box - NOTE: if the user makes a mistake, they will need to use the reset button there is no way of identifying which attachment to remove after that have been added.
    Collect(
        colAttach,
        ThisItem.Attachments
    )
    The Items of the Attachment control
    colAttach
    and the email Attachments code
    Attachments: 
    ForAll(
       colAttach As _AC,
       {
          Name: _AC.DisplayName,
          ContentBytes: _AC.Value
       }
    )

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee

     
     
  • WarrenBelz Profile Picture
    152,843 Most Valuable Professional 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 836 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 231 Super User 2025 Season 2

Last 30 days Overall leaderboard