Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Server Code Query By Username & Date

Hi EJLD,

Unfortunatly we can not write code for users. But can help with it..

Please try to debug this code with codeconsole.log();/code and tell us where you have a problem and what is not work.

Regards.

EJLD
Posts: 0
Joined: Sun Jun 08, 2014 11:03 pm

Server Code Query By Username & Date

Hi Yurii,

Yes, I know you guys are not supposed to debug code for clients.
However, 2 things I'd like to say:
. when the builder is upgraded several part of the code which were working well were messed up and I had to amend by myself, it consumed very much of my time, and delayed seriously my schedule.
. that part of server code came from you, not working.
I'm just asking some help with the syntax to get started ... expected more understanding from your side.

anyway ...
I looked into it already with console.log();
it seems that the execution goes well within the first query through the outter for-loop but information doesn't enter the 2nd for-loop. don't know if that's clear enough. I am sure it must be very small things to solve for sb who knows but since I hv never touch that part of server stuff, it will take me ours.

tell me if you cld do something however,

thk you in advance,

Eric

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Server Code Query By Username & Date

EJLD,

Try to understand whether you have correct query for second collection and whether you have correct second collection query result.

Code example with console.log for this goal.

pre

var DB_id = "52fdxxxxx1c89917",
collectionName = "dogs",
columnNamePlayer1 = 'name',
columnNameScore = 'number';
try {
var result = [];
query1 = Collection.distinct(DB_id, collectionName, columnNamePlayer1);
for (var j = 0; j < query1&#46;length; j++) {
var params = {}; &#47;&#47;Define parameters object
params&#46;criteria = { &#47;&#47;Query criteria:
'name': query1[j]
};
var query2 = Collection&#46;query(DB_id, collectionName, params);

Code: Select all

 console&#46;log("params = "); 
 console&#46;log(JSON&#46;stringify(params)); 

 console&#46;log("query2 = "); 
 console&#46;log(JSON&#46;stringify(query2)); 

 var i, len, value; 
 var sum = 0; 
 for (i = 0, len = query2&#46;length; i < len; i++) { 
   value = parseFloat(query2[i][columnNameScore]); 
   if (value) sum += value; 
 }; 
 result&#46;push({ 
   Player: query1[j], 
   totalSum: sum 
 }); 

}
response&#46;success(result, "application/json");
} catch (e) {
response&#46;success({
message: e&#46;message,
code: e&#46;code
}, "application/json");
}

/pre

Regards.

EJLD
Posts: 0
Joined: Sun Jun 08, 2014 11:03 pm

Server Code Query By Username & Date

Hi Yurii,
Thks for your prompt reply.
Wrong field name.
It works now.
Best,
Eric

EJLD
Posts: 0
Joined: Sun Jun 08, 2014 11:03 pm

Server Code Query By Username & Date

Hi Yurii, just to tell you that I did succeed at building my first server code script. it executes several queries ... and create records ... over several different tables ... on schedule! thks for your very much appreciated help to get started. Eric

Return to “Issues”