question

kitchristopherpro avatar image
kitchristopherpro asked

How to set Title Data as a dict of arrays

Hello,

I'm trying to store title data as a dictionary to an array, where the key is a requestee email, and the value is the array of requester emails, something like this as pictured below:


However, I'm not quite sure of the proper javascript and cloud code to add new values or update existing. Can someone please give an example of the code? This is what I've been experimenting with, but I always get an error when trying to set title data.

CloudScript
10 |1200

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

kitchristopherpro avatar image
kitchristopherpro answered
	I get an error when I call SetTitleData. I think the emailsDict needs to be converted into a string, but trying JSON.stringify(emailsDict) didn't work either.

var emailsDict = {}; var requesterEmails = []; requesterEmails[0] = args.requesterEmail; emailsDict[args.requesteeEmail] = requesterEmails; var setTitleDataRequest = { "Keys": "PendingInviteList", "Value": emailsDict }; var setTitleDataResponse = server.SetTitleData(setTitleDataRequest);
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.

Gosen Gao avatar image Gosen Gao commented ·

Please replace the setTitleDataRequest with the code below and try again.

var setTitleDataRequest = {
        Key:"PendingInviteList",
        Value:JSON.stringify(value)
    }
0 Likes 0 ·
kitchristopherpro avatar image
kitchristopherpro answered

I apologize, the pictures didn't save in my original post. Here they are here.

cloudcode.png
idealdata.png


cloudcode.png (136.2 KiB)
idealdata.png (25.8 KiB)
10 |1200

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

Gosen Gao avatar image
Gosen Gao answered

Code below shows three ways to implement your needs, you can have a look.

let res = {}
//let emails = new Array("test0@test.com","test1@test.com")
//let emails = ["test0@test.com","test1@test.com"]
let emails = []
emails[0] = "test0@test.com"
emails[1] = "test1@test.com"
res["requesteeEmailKey"] = emails
10 |1200

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

kitchristopherpro avatar image
kitchristopherpro answered

Awesome, that got it working! Thanks so much!!!

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.