question

plantsist avatar image
plantsist asked

Auto AddMembers Via CloudScript

I'm having trouble to addMembers Via CloudScript,

I've found some codes from the forum but they seem to not be working.

I'm not if it is because I'm not using the correct APIs or what.

Is it possible if someone can give me some guidance and if possible could someone kinda instruct me how to call APIs such as AddMember request in cloud script.

Here is a snippet of my code from the revision area

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.

plantsist avatar image plantsist commented ·

Couldn't upload a snippet so here are my codes

handlers.addMember = function (args, context){

//let group = {Id: args.groupEntity, Type: "group"}

//let entityProfile = context.currentEntity;

//entity.AddMembers({Group: group, Members: [entityProfile.Entity]});

var request = { group: args.groupEntity, entityProfile: [context.currentEntity] };

var AddMembers = server.AddMembers(request); }

0 Likes 0 ·

1 Answer

·
Seth Du avatar image
Seth Du answered

I assume you are using ExecuteEntityCloudScript API to call the function because there won’t be entity related information in the context if using ExecuteCloudScript. You may compare the context value via “return context;”.

As you can see in the document -- Groups - Add Members (PlayFab Groups) | Microsoft Docs, the property “Members” is a list of Entity Key, while the context.currentEntity is the profile of the entity, which means it not only contains Entity Key, but also contains many other information like Objects, EntityChain, etc.

Hence, you may replace the following code.

var request = { group: args.groupEntity, entityProfile: [context.currentEntity] };

and use the below code instead:

var request = { Group: args.groupEntity, Members: [context.currentEntity.Entity] };

BTW, the code you have commented seems to be correct. May I ask why the change?

10 |1200

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

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.