question

betweenmatt avatar image
betweenmatt asked

Getting ItemInstanceId from GrantItemsToUser,Returning ItemInstanceId from GrantItemToUser

Hey!

I've been having an issue with getting ItemInstanceId from the result of GrantItemsToUser call in cloudscript. I can not get it to return anything but Null - even though it is definitely granting the item to the user. Honestly, I'm betting it's just a simple JavaScript error, but I'm not well versed in JavaScript enough to figure it out. Thank you for your help!

var pull = server.GrantItemsToUser({ "PlayFabId": currentPlayerId, "ItemIds": [lastId] });
        var results = pull.ItemGrantResults;
        var instId = results.ItemInstanceId;
        return { message: instId };
,

Hey!

I've been having an issue with getting the ItemInstanceId from the result of GrantItemToUser in cloudscript - no matter what I try it keeps returning Null, even though it's most definitely granting the item. Honestly, I think it's most likely something I'm doing wrong in JavaScript, but I'm not well versed enough in JavaScript to figure it out. Thank you for your time!

var pull = server.GrantItemsToUser({ "PlayFabId": currentPlayerId, "ItemIds": [lastId] });
        var results = pull.ItemGrantResults;
        var instId = results.ItemInstanceId;
        return { message: instId };

CloudScript
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.

betweenmatt avatar image betweenmatt commented ·

I'm sorry, I thought my original post got lost so i wrote it again and it combined them @.@ and for the life of me cant figure out how to edit a post lol

0 Likes 0 ·

1 Answer

·
Joshua Strunk avatar image
Joshua Strunk answered

server.GrantItemsToUser takes an array of itemIds and returns an array grant results. You need to get one of the GrantedItemInstances from the array.

var firstGrantedItemReturned = pull.ItemGrantResults[0];
var firstGrantedItemID = firstGrantedItemReturned.ItemInstanceId; 

I would add range and null checks to this for safety.

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.

Joshua Strunk avatar image Joshua Strunk commented ·

A side note, do not rely on the order of grant results returned to match the order of ItemIds passed in.

0 Likes 0 ·
betweenmatt avatar image betweenmatt commented ·

Wow! Thank you so much! I can't believe something so simple had me stuck for so long lol

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.