Page 1 of 2

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

Posted: Thu Jul 10, 2014 4:29 pm
by Andy6966317

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


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

Posted: Thu Jul 10, 2014 5:03 pm
by Evgene Karachevtsev

Hello Andy,

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


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

Posted: Thu Jul 10, 2014 5:14 pm
by Andy6966317

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


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

Posted: Thu Jul 10, 2014 9:05 pm
by Evgene Karachevtsev

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


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

Posted: Thu Jul 10, 2014 9:54 pm
by Andy6966317

Image Image Image

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


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

Posted: Fri Jul 11, 2014 8:57 am
by Maryna Brodina

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


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

Posted: Fri Jul 11, 2014 3:06 pm
by Andy6966317

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


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

Posted: Fri Jul 11, 2014 6:13 pm
by Evgene Karachevtsev

Hello Andy,

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


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

Posted: Fri Jul 11, 2014 6:28 pm
by Andy6966317

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


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

Posted: Fri Jul 11, 2014 7:23 pm
by Evgene Karachevtsev

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.