Page 2 of 3
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 3:54 am
by maxkatz
If you don't have strong background in JavaScript, the easiest way would be to define a REST service, get all the data and display only the columns that you need. This can be done in under 10 minutes usually...
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 3:54 am
by Christopher Herold
I am taking a closer look at the JSON.stringify data that I now have. I have noticed that the order in which it is outputted is NOT according to the order of the columns in the database, but alphabetically. Why? Is there a way to output the JSON data so that it follows the order of the database columns?
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 4:38 am
by Christopher Herold
Ok, I set up a REST service. Named it "REST Request". It is a GET and it works ... I tested it. Problem is that in the Response tab, I only listed the four items I wanted to pull down, but in the test output it still pulled down all of the columns for each row. What do I have to do to have it only show what I list under the Reponse tab?
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 4:39 am
by Christopher Herold
And how do I make it so it doesn't output the columns alphabetically?!
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 4:46 am
by maxkatz
When you test it will show the entire JSON response. If you defined only specific columns in the response, then only those will be available when you do mapping.
The objects should be in the same order as they are created in the database. Check the database docs, you can sort the result.
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 5:23 am
by Christopher Herold
But I don't want to do mapping. I am taking the entire JSON response and packing it into one variable (that I am then sending out by email).
I know I can sort the result of the entries (rows) but I don't see a way to sort the column headers (or leave them in their default order, as arranged in the database). If you have a reference in the documentation that shows how to sort the column headers let me know, but even doing the simple test run for the REST Service they come out alphabetically.
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 4:54 pm
by maxkatz
Can you post a screen shot of how your database columns look, how the data looks and what order you need?
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 7:15 pm
by Christopher Herold
Hi Max,
You can see the database structure in the top of the screenshot and then a JSON retrieval of the database information in the bottom and how it is ordered alphabetically.
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 9:58 pm
by maxkatz
Do you refer to the fields (columns) in the return JSON object?
Saving a database list into a local variable.
Posted: Mon Nov 11, 2013 11:59 pm
by Christopher Herold
I am not sure what you mean. The return JSON object contains the database output that I have selected for using a where statement. I am getting it by
code
var response = JSON.stringify(data);
localStorage.setItem("json_response", response);
/code
Let me know if this is not what you meant.