question

FatPanda avatar image
FatPanda asked

"GetUserReadOnlyData" server method returns empty data.

So I made a simple CloudScript method to get User ReadOnly Data:

handlers.CheckQuestsDate = function(args)
{  
var result = server.GetUserReadOnlyData({"PlayFabId" : currentPlayerId, "Keys" : ["QuestList"]});  

log.info(result);

var questObject = JSON.parse(result.Data["QuestList"].Value);
  
  var LastTimeCompleted = Date.parse(questObject.playerQuestList[0].timeWasActivated);
  var DaysSinceLastCompletion = CalculateDayDifference(LastTimeCompleted, Date.now());
  var retObj = {};
  
  if (DaysSinceLastCompletion <= 1) 
  {
     retObj["Success"] = true;
  }else
  {
    retObj["Success"] = false;
  }
  return retObj;

};

When I execute ExecuteCloudScript with the "Try it" button with the function name = "CheckQuestsDate" as parameter, I get :

{
 "code": 200,
 "status": "OK",
 "data": {
  "FunctionName": "CheckQuestsDate",
  "Revision": 43,
  "Logs": [
   {
    "Level": "Info",
    "Message": "{\"PlayFabId\":\"12BA3CBC081A2BC1\",\"DataVersion\":0,\"Data\":{}}"
   }
  ],
  "ExecutionTimeSeconds": 0.0363576,
  "ProcessorTimeSeconds": 0,
  "MemoryConsumedBytes": 49152,
  "APIRequestsIssued": 1,
  "HttpRequestsIssued": 0,
  "Error": {
   "Error": "JavascriptException",
   "Message": "JavascriptException",
   "StackTrace": "TypeError: Cannot read property 'Value' of undefined\n    at handlers.CheckQuestsDate (FB3E-main.js:303:56)"
  }
 },
 "CallBackTimeMS": 415
}

As you can see, the Data field is empty (and can´t get the Value field in my method so I get theTypeError). However when I use GetUserReadOnlyData with the sample request "Try it" button with Keys = QuestList and PlayFabId = AB006BF1C23FFA63 as parameters I get this:

{
 "code": 200,
 "status": "OK",
 "data": {
  "PlayFabId": "AB006BF1C23FFA63",
  "DataVersion": 636,
  "Data": {
   "QuestList": {
    "Value": "{\"playerQuestList\":[{\"id\":8,\"currentProgress\":0,\"timeWasActivated\":\"Wed, 13 Jun 2018 20:46:50 GMT\"},{\"id\":1,\"currentProgress\":0,\"timeWasActivated\":\"Wed, 13 Jun 2018 20:46:50 GMT\"},{\"id\":6,\"currentProgress\":0,\"timeWasActivated\":\"Wed, 13 Jun 2018 20:46:50 GMT\"}]}",
    "LastUpdated": "2018-06-13T20:46:50.356Z",
    "Permission": "Private"
   }
  }
 },
 "CallBackTimeMS": 562
}

You can see that data is not empty. I need this data to compare Dates, however it´s always empty any help is welcome, thanks!

apis
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

You actually have two completely different PlayFab IDs between your two response examples. Can you please specify what the Title ID is that you're testing, and the PlayFab ID of the user you're trying to test with your handler? In our own testing, the call to read Player Read Only Data returns the data in Cloud Script, the TryIt option in the doc pages, and via direct API calls.

2 comments
10 |1200

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

FatPanda avatar image FatPanda commented ·

Yeah sure, the Title ID is FB3E and the PlayFab ID of the user (me) is AB006BF1C23FFA63. In the meantime I made a workaround to get the my data from the client (with GetUserReadOnlyData) and execute the method I need in the cloud with that data. I know this is not the best way, for a lot of reasons, but it worked. Anyway thanks for the help!

0 Likes 0 ·
brendan avatar image brendan FatPanda commented ·

I just copied the Cloud Script handler code from above to my own test title, and copied your player's read only data for QuestList into a test player, and the script worked fine for me to read the data (granted, I didn't have CalculateDayDifference, so it stopped there, but the data was fine).

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.