Metadata out of sync error after updating User through JavaScript

Hi,

I'm updating a user through JavaScript ilke this:

Fullscreen
1
2
3
const userBean = app.data.createBean('Users', {id: app.user.id});
userBean.set('has_read', true);
userBean.save();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The save operation works, but after the user has been updated I keep getting 'metadata out of sync error', till I refresh the browser.

Fullscreen
1
2
3
4
5
6
{
error: "metadata_out_of_date"
error_message: "Your metadata or user hash did not match the server. Please resync your metadata."
metadata_hash: "f86c8baca62aea11496e614fe9710954"
user_hash: "102b9d1cd65dbe95f50ddfd6b2a45bc5"
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

What am I missing?

I'm working on Sugar 11.x

Any help appreciated. Thank you.

Volkan

  • We implement a feature for a customier which updates data of the authenticated portal user id via server side and it works without a big deal. We never tried updating via client side. Perhaps it is a clue.

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Just in case anybody needs a solution for this problem.

    I've solved it by adding following line after the user save operation:

    Fullscreen
    1
    app.user.load();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Cheers!

  • Another alternative would be to just call following code to update the current user:

    Fullscreen
    1
    app.user.update('update', {'has_read': true}, function() { console.log('update successful'); });
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    instead of

    Fullscreen
    1
    2
    3
    4
    const userBean = app.data.createBean('Users', {id: app.user.id});
    userBean.set('has_read', true);
    userBean.save();
    app.user.load();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX