Andy6966317
Posts: 0
Joined: Fri Jul 04, 2014 2:39 am

how to pass a String into an Array to create a list of the strings.

I am trying to store user IDs in a single group array with the column type array.

As a user joins a group, I want their ID added to the array.

I understand that when I am mapping local variables (where the userID is stored) to a request parameter that I need to include some of my own code as well in order to get it to pass into the array.

I am very new to javascript and appery.io so any help is appreciated!

column name name is membersIDs

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

how to pass a String into an Array to create a list of the strings.

Hello Andy,

Please look at this link, information there should be useful: http://devcenter.appery.io/documentat...

Andy6966317
Posts: 0
Joined: Fri Jul 04, 2014 2:39 am

how to pass a String into an Array to create a list of the strings.

I have read that and can't seem to figure it out.

I am putting this JS into the mapping of membersIDs:

{"__op":"AddUnique","objects":[ ID ]}}'

Then I am adding a level under membersIDs in the requests part of the service that says ID.

What I want is for the value mapped to ID from a local variable to be put into the array if it is not already there (hence the AddUnique).

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

how to pass a String into an Array to create a list of the strings.

Andy,

You should make mapping of the necessary value in request parameter with the desired array, and add this code in mapping

codereturn {"__op":"AddUnique","objects":[value]};/code

Andy6966317
Posts: 0
Joined: Fri Jul 04, 2014 2:39 am

how to pass a String into an Array to create a list of the strings.

Image Image Image

Maybe these will help.
I tried your solution to no avail.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

how to pass a String into an Array to create a list of the strings.

Hello!

The problem is that in members localStorage variable is stored object which contains firstName, lastName and ID. But entire object is stored in string, that's why in mapping to this parameter from localStorage add the following code: prereturn JSON.parse(value);/pre

Andy6966317
Posts: 0
Joined: Fri Jul 04, 2014 2:39 am

how to pass a String into an Array to create a list of the strings.

Thanks for the help so far!
I'm still struggling a bit.

Did the platform autocreate that localVariable "members"?
I don't recall ever creating such a variable.

Does this screenshot change your answer?
The Javascript inserted into the membersIDs request is what Maryna suggested above.

Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

how to pass a String into an Array to create a list of the strings.

Hello Andy,

If you do the mapping, then you should remove js code which Marina advised to use

Andy6966317
Posts: 0
Joined: Fri Jul 04, 2014 2:39 am

how to pass a String into an Array to create a list of the strings.

Then JS Code do I use? And where do I put it?
I have tried: return {"__op":"AddUnique","objects":[value]};
I have also tried: return JSON.parse(value);

Merely mapping like below gives me NO results in the database:

Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

how to pass a String into an Array to create a list of the strings.

Andy

Could you please clarify something. Judging by the screenshot of dB members is an array. What will you keep in it and why in the service in members there are embedded fields? In the array you can keep only simple data types (strings, numbers, boolean), objects can't.

Return to “Issues”