question

leafsas2015 avatar image
leafsas2015 asked

Delete User ReadOnlyData with Cloud Script

Hi! i'm trying to manage ReadOnly user data with cloud script, i made a javascript code to update userdata, and it works. I'm trying to make a script to remove specific key from data, but it does not work, any suggestions? thanks!!

handlers.sendFriendRequest = function (args) {
    ProcessSendRequest(args.id, args.senderId, args.senderName);
};


handlers.removeFriendRequest = function (args) {
    ProcessRemoveFriend(args.id, args.senderId);
};


function ProcessSendRequest(id, idSender, nameSender) {
    var UpdateUserReadOnlyDataRequest = {
        "PlayFabId": id,
        "Data": {},
        "Permission": "Public"
    };
    UpdateUserReadOnlyDataRequest.Data[idSender] = JSON.stringify(nameSender);
    var UpdateUserReadOnlyDataResult = server.UpdateUserReadOnlyData(UpdateUserReadOnlyDataRequest);
}


function ProcessRemoveFriend(id, value) {
    var UpdateUserReadOnlyDataRequest = {
        "PlayFabId": id,
        "KeysToRemove": [],
        "Permission": "Public"
    };
    UpdateUserReadOnlyDataRequest.KeysToRemove[value] = JSON.stringify(value);
    var UpdateUserReadOnlyDataResult = server.UpdateUserReadOnlyData(UpdateUserReadOnlyDataRequest);
}
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

With the UpdateUserReadOnlyData call using the Data parameter, you're adding to a JSON object that describes the key/value pairs. So, if idSender is "1" and nameSender is "A", you're adding the key/value "1": "A" to the object, so that's all good.

But the KeysToRemove parameter is not an object - it's an array. Right now, your code is trying to set the key/value pair value:value. What you want there is to use push to add value to the array.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

leafsas2015 avatar image leafsas2015 commented ·

Thanks, i have solved :) and it works

function ProcessRemoveFriend(id, value) {


    var UpdateUserReadOnlyDataRequest = {
        "PlayFabId": id,
        "KeysToRemove": value,
        "Permission": "Public"
    };
    var UpdateUserReadOnlyDataResult = server.UpdateUserReadOnlyData(UpdateUserReadOnlyDataRequest);
}
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.