araskin3i
Posts: 0
Joined: Fri Dec 20, 2013 2:44 pm

Append values to a database array field

I have the following code in a server code service:
code
var globalTaxItems = Collection.query(DB_id, "taxCodes", taxItemParams );
for (var m = 0; m < globalTaxItems&#46;length; m++) {
aTaxItem = globalTaxItems[m];
myHeaderItem&#46;taxItems&#46;push(aTaxItem);
}
/code

menuItem.taxItems is an array field defined in the database collection. I am trying to append values to it. When I run this script it tells me that 'push' is not defined. I am guessing this means that taxItems is not an ARRAY (in the traditional JavaScript sense). Can you suggest how I can append values to this field so I can return it in the REST API that I am writing?

araskin3i
Posts: 0
Joined: Fri Dec 20, 2013 2:44 pm

Append values to a database array field

I should also add that I did try to convert the JSON object into a standard JS object BEFORE calling 'push' as shown below. Unfortunately the code raises an exception 'Unexpected end of Input' when I call JSON.parse in the first line

code
&#47;&#47;the line below raises an exception
jsonObjTaxItems = JSON&#46;parse(myHeaderItem&#46;taxItems);
console&#46;log('All done&#46;');

/code

obullei
Posts: 0
Joined: Thu Jun 05, 2014 12:17 am

Append values to a database array field

Hello Arshkini3i!

We are working on it at the moment and will get back to you with update as soon as possible.

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

Append values to a database array field

Hello

Please clarify how do you initialize the variable myHeaderItem? Can you please provide the full text of the script or a screenshot.

araskin3i
Posts: 0
Joined: Fri Dec 20, 2013 2:44 pm

Append values to a database array field

Hi Evgene,

The myHeaderItem is a line from a call to

code
myCategory&#46;headerItems = Collection&#46;query(DB_id, "headerItems", headerItemsParams); &#47;&#47;Make the query

Code: Select all

 for (var k = 0; k < myCategory&#46;headerItems&#46;length; k++) { 

   var headerItem = myCategory&#46;headerItems[k]; 

/code

I will email the full code to a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a as I do not want to provide the code publicly.

Regards,

Alon

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

Append values to a database array field

Hello Alon,

Could you please check is JSON string with description of the array in menuItem.taxItems correct? Please clarify what value of menuItem.taxItems do you get in console? What type of column taxItems in collection?

araskin3i
Posts: 0
Joined: Fri Dec 20, 2013 2:44 pm

Append values to a database array field

Could you please check is JSON string with description of the array in menuItem.taxItems correct?

I am not sure I understand what you mean?

Please clarify what value of menuItem.taxItems do you get in console?
I get this in the console log which is correct since taxItems are empty array

code[]/code

What type of column taxItems in collection?
taxitems is a column of type array in the collection

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

Append values to a database array field

Hello,

You shouldn't do

codeJSON&#46;parse(menuItem&#46;taxItems);/code

because menuItem.taxItems is array itself.

Return to “Issues”