i just got a requirement to modify some code in my SPFX app to detect a user sessions. the requirements is that i have to lock that specific list which is tracked by a separate tracking list (schema: listname, lockedBy) so currently on button click of the app, i will trigger the code to update the tracking list with the current user. then on save button click, it will release and remove the lockedBy in the tracking list:

code that does this is straighforward:

public lockList (currentUser: any, division: string, qnaListTrackingListName: string) : Promise<any>{
        let d = moment.utc().local().format("MM/DD/YYYY HH:mm");
        return sp.web.lists.getByTitle(qnaListTrackingListName).items.top(1).filter("Division eq '" + division + "'").get().then((items: any[]) => {

            if (items.length > 0) {
                return  sp.web.lists.getByTitle(qnaListTrackingListName).items.getById(items[0].Id).update({
                    LockedById: currentUser.Id,

                }).then(result => {
                    return result;
                }).catch(error => {
                    return error;
       // return res;

so now, i have to check that if the user failed to save the item, then i would have to update the item after 10 min or so to remove his name in the LockedBy column.

is this possible?


Front end code like this runs in the browser, so if a user navigates away or closes the browser, the code is gone. So you won't be able to achieve what you want with this approach.

You're going to need a backend approach, like a timer job, to do the unlocking.

For what it's worth this seems like a really janky architecture and is going to cause you untold maintenance grief. Also your users will be able to bypass your web part altogether and go direct to the list and you won't be able to stop them. If I were you I'd reconsider this approach and try to solve the business problem (whatever it is) in a more sustainable manner.

  • i have come up with a fairly simple solution for this one by adding event listeners on the app itself and clearing the timeout everytime the user is using the app. but i just don't get why the requirement needs to be on browser close. – Page F.P.T Nov 13 '18 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.