Page 1 of 1

Append values to a database array field

Posted: Sat Jun 14, 2014 11:23 am
by araskin3i

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?


Append values to a database array field

Posted: Sat Jun 14, 2014 11:41 am
by araskin3i

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


Append values to a database array field

Posted: Sat Jun 14, 2014 2:02 pm
by obullei

Hello Arshkini3i!

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


Append values to a database array field

Posted: Mon Jun 16, 2014 9:17 am
by Evgene Karachevtsev

Hello

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


Append values to a database array field

Posted: Mon Jun 16, 2014 1:57 pm
by araskin3i

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


Append values to a database array field

Posted: Tue Jun 17, 2014 8:20 am
by Evgene Karachevtsev

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?


Append values to a database array field

Posted: Tue Jun 17, 2014 12:47 pm
by araskin3i

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


Append values to a database array field

Posted: Wed Jun 18, 2014 1:18 pm
by Evgene Karachevtsev

Hello,

You shouldn't do

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

because menuItem.taxItems is array itself.