question

Jannick Leismann avatar image
Jannick Leismann asked

Return item instanceID from cloud script

Hey there,

I want my Cloud Script to return the instanceID of the item that got created within the call:

handlers.grantItem = function (args, context){
    
    
    var request = {
        ItemGrants: [{
            PlayFabId: currentPlayerId,
            ItemId: args,
            Data: {
                    "Equipped": "false"
                  }
        }]
    
    };
    
    var playerGrantItemsResult = server.GrantItemsToUsers(request);

    
    return {playerGrantItemsResult }; // Return the instanceID of the item here

}


Any approach?

Greets

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.

JayZuo avatar image JayZuo ♦ commented ·

This will depend on how many items you've granted. If there will only be on item, then you can get the instance id like

return playerGrantItemsResult[0].ItemInstanceId
0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

Could you please tell us how do you test your CloudScript? Do you use execute CloudScript in Unity? What's the result of your code? And as Jay said, playerGrantItemsResult is a JSON Array, so you can't get the ID directly.

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.

Jannick Leismann avatar image Jannick Leismann commented ·

Hi, yes I use execute CloudScript in Unity. I receive a json string with the entire result (that looks totally fine).

I'll try this approach:

return playerGrantItemsResult[0].ItemInstanceId

Greets

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.