Search code examples
powerappssharepoint-list

Update items to SP List using patch in Power Apps


I am trying to edit the existing template for the Service Desk app but changing the data source to a Share Point list vs. the default table the template opens with. Can someone please help me understand how I can code the logic where it takes the existing tickets screen (I currently am retrieving data on the 'all tickets' page from my SP list) data and allows you to click/transition to another page where you can change parameters by additional clicks that will update the values on the SP list? The code out of the box looks like -

EditForm(TicketDetailsForm);
Navigate(TicketdetailsPage_1,ScreenTransition.Fade,
    {EditRecord:ThisItem,
    type:ThisItem.task_status,
    assign:ThisItem.assignedto,
    Area:ThisItem.department,
    priority:ThisItem.priority,
    subjectdisabled:true,
    subjectfill:RGBA(0,0,0,0),
    subject_visible:true,
    description_disabled:true,
    description_bordercolor:RGBA(0,0,0,0),
    description_fill:RGBA(0,0,0,0),
    description_visible:true,
    commentdisabled:true,
    commentbordercolor:RGBA(0,0,0,0),
    commentfill:RGBA(0,0,0,0),
    commentvisible:true})

and I am trying a variant of syntax using Patch that looks like

Patch(
    sharepoint_list_name,  
    LookUp(
        sharepoint_list_name,  SharePoint list
        ID = ThisItem.ID  
    ),
    {
        task_status: Text(ThisItem.task_status),
        assignedto: Concatenate(
          "i:0#.f|membership|",
          User().Email // Person email
          ),
          Department: "",
          DisplayName: User().FullName,
          Email: User().Email, // Person email
          JobTitle: "",
          Picture: "",
        department: Text(ThisItem.department),
        priority: Text(ThisItem.priority)
        // Add more fields to update here as needed
    }
);

Navigate(
    TicketdetailsPage_1,
    ScreenTransition.Fade,
    {
        EditRecord: ThisItem,
        type: Text(ThisItem.task_status),
        assign: Concatenate(
          "i:0#.f|membership|",
          User().Email // Person email
          ),
          Department: "",
          DisplayName: User().FullName,
          Email: User().Email, // Person email
          JobTitle: "",
          Picture: "",
        Area: Text(ThisItem.department),
        priority: Text(ThisItem.priority),
        subjectdisabled: true,
        subjectfill: RGBA(0, 0, 0, 0),
        subject_visible: true,
        description_disabled: true,
        description_bordercolor: RGBA(0, 0, 0, 0),
        description_fill: RGBA(0, 0, 0, 0),
        description_visible: true,
        commentdisabled: true,
        commentbordercolor: RGBA(0, 0, 0, 0),
        commentfill: RGBA(0, 0, 0, 0),
        commentvisible: true
    }
)

I honestly have no idea what the logic is doing here - I don't understand how the default table data allows the user to click the window and transition to another page where items can be selected and have the values update. I am just trying to accomplish the same thing but with a SP list. Anything here would be greatly appreciated. Thank you.

These are my SP column names/types

assignedto - person/group
priority - choice 
department - choice
task_status - choice

Solution

  • The high level logic is this:

    1. The 'All tickets' page has a DataTable or Gallery control showing all the tickets. From this page, clicking on the controls that have the Navigate functions. The Navigate syntax also passes the selected ticket's details as an argument to the ticketform screen where this record becomes a local variable referenced in the controls showing the current values of the ticket.
    2. After editing ticket details there's (I guess) a submit button to save the changes. This is where the Patch() function should be. Until the user clicks the button the changes are only in Power Apps. When the Patch() runs, they are saved in SharePoint too. Note that the 'assignedto' field is a Person or Group field and it requires that the user's data is sent as a record as in your template app. When the data is saved, the list of tickets will be also updated automatically in the app.

    2 things to change:

    • to replace the data source with your SharePoint list, you need to change the gallery/datatable's Items property, and the Patch function too. Pay attention to the field names, if you only have 4 fields, you can remove most of the code from the original patch function.
    • after the Patch runs, it is recommended that you use Notify() to provide the user some feedback and Navigate() to go back to the 'All tickets' screen.