Power Apps - Patch not updating Sharepoint List (creates record, but won't update)

Viewed 442

I've got a Power App which allows users to answer "Yes/No" on a series of questions from a gallery and update a Sharepoint list by either adding a new record or updating the existing record. Adding a new record works fine, but the script won't update any existing record.

Key: 'Finance Skills Assessment - Responses' - The sharepoint list name (currently 30,000+ records) UserResponses = a collection based on the users responses to the sharepoint list (about 142 records maximum and set on app open and when the user enters the relevant page)

This is the part of my script which isn't working - any help would be greatly appreciated!:

ForAll(QuestionList.AllItems,

If(!IsBlankOrError(
                    LookUp(UserResponses,UniqueRef = 
                        Concatenate(QuestionIDBox.Text,CurrentUserEmail)
                        )),
    Patch('Finance Skills Assessment - Responses', LookUp('Finance Skills Assessment - Responses', UniqueRef = Concatenate(QuestionIDBox.Text,CurrentUserEmail)), 
        { 
        Response: If(YesNo.Value=true,"Yes","No"),
        Timestamp: Now()
        }),

    Patch('Finance Skills Assessment - Responses', Defaults('Finance Skills Assessment - Responses'),
        { QuestionID : QuestionIDBox.Text , 
        Response: If(YesNo.Value=true,"Yes","No"),
        Timestamp: Now(),
        UserPrinciple: CurrentUserEmail,
        UniqueRef: Concatenate(QuestionIDBox.Text,CurrentUserEmail)
        })
)

)

1 Answers

I find that using Patch inside a ForAll, or even a gallery can be a bit tricky.

What works for me most times is instead of using the LookUp() function in the ForAll, I simply only use {ID: Value(hiddenLabel.Text)} and also {ID: ThisRecord.ID}

You could try:

ForAll(QuestionList.AllItems,

If(!IsBlankOrError(
                    LookUp(UserResponses,UniqueRef = 
                        Concatenate(QuestionIDBox.Text,CurrentUserEmail)
                        )),
    Patch('Finance Skills Assessment - Responses', {UniqueRef: Concatenate(QuestionIDBox.Text,CurrentUserEmail)}, 
        { 
        Response: If(YesNo.Value=true,"Yes","No"),
        Timestamp: Now()
        }),

Patch('Finance Skills Assessment - Responses', Defaults('Finance Skills Assessment - Responses'),
    { QuestionID : QuestionIDBox.Text , 
    Response: If(YesNo.Value=true,"Yes","No"),
    Timestamp: Now(),
    UserPrinciple: CurrentUserEmail,
    UniqueRef: Concatenate(QuestionIDBox.Text,CurrentUserEmail)
    })
)
)
Related