0

I'm working with a table in Azure Mobile Services using the Javascript Library that has soft delete enabled. The delete part works fine, but the undelete is causing me issues. I've looked all over, and can't seem to find any documentation on how to actually undelete a soft deleted record. I resorted to trying updating the record and setting the __deleted field to false, but this just returns a 412 error "Precondition Failed".

     function addUser(user) {

        return $q(function (resolve, reject) {
            var users = aadClient.getTable("user");
            var newUser = { id: user.userPrincipalName, name: user.givenName + " " + user.surname };

            users.where({ id: user.userPrincipalName })
                .read({ __includedeleted: true })
                .done(function (results) {
                    if (results.length < 1) {
                        users.insert(newUser).done(function (result) {
                            resolve(result);
                        }, function (err) {
                            reject(err);
                        });

                    } else {
                        results[0].__deleted = false;
                        users.update(results[0]).done(function (result) {
                            resolve(result);
                        }, function (err) {
                            reject(err);
                        });

                    }

                });

        })

    }

1 Answer 1

1

Undelete is a POST to /table/tablename/recordId. It looks like we didn't add that method in the JS SDK yet. So it may be quickest to do an ajax request directly to do that.

You could also look at updating your table's insert script to capture the conflict, and just resolve it during the insert process and leave the client out of the picture. This is the path I would recommend.

(Let me know the backend type you are using, and I can see if I can post a snippet of how to do so if needed)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the quick response. I'm using the JavaScript backend. Quick follow up question. The documentation makes reference to the ability to delete an undelete request(request.undelete) on the server, but this also seems to not work. Is there some secret to get this to work as well?
That worked! Only thing I will note is the body of the POST request has to be blank.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.