kabrams
Posts: 0
Joined: Mon Nov 18, 2013 2:05 am

"edit js' code on where for query which takes input values for 2 variables and does collection lookup, then allows anoth

Hello, I'm trying to set up input search criteria on 2 fields, then based on input values, search collection then perform average on each field. I have my javascript [to calculate average] working but I'm not sure what the code for the 'edit js' button on 'where' request should be.

This is my 'edit js' code on 'where' request but I don't think it's right. I have another js running on event for service which calculates the average.

console.log('{"incident_state":"' + Appery('report_input_state').val() + '", "incident_county":"'+Appery('report_input_county').val()+'"}');
return '{"incident_state":"' + Appery('report_input_state').val() + '", "incident_county":"'+Appery('report_input_county').val()+'"}';

Does that 'edit js' look right? it's mapping to a storage variable called 'where'

kabrams
Posts: 0
Joined: Mon Nov 18, 2013 2:05 am

"edit js' code on where for query which takes input values for 2 variables and does collection lookup, then allows anoth

On success event, I'm running this js to get average as a letter grade.

var correspondence = "FDCBAA"; // last A is for a perfect 5
var courtesyVal = 0, overallVal = 0;

if (data.length) {
for (var i = 0; i < data.length; i++) {
courtesyVal += data.grade_courtesy;
overallVal += data.grade_overall;
}

courtesyVal = (courtesyVal / data.length);
overallVal = (overallVal / data.length);
}

courtesyVal = correspondence[Math.floor(courtesyVal)];
overallVal = correspondence[Math.floor(overallVal)];

Appery("courtesy_grade").text(courtesyVal);
Appery("overall_grade").text(overallVal);

kabrams
Posts: 0
Joined: Mon Nov 18, 2013 2:05 am

"edit js' code on where for query which takes input values for 2 variables and does collection lookup, then allows anoth

seriously? use this where? in the editjs? in the calculation js? Where and how? Your response is cryptic. I've almost got this working. I just need a little help.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

"edit js' code on where for query which takes input values for 2 variables and does collection lookup, then allows anoth

Hello - here is shown how to use $and operator: http://docs.appery.io/documentation/b...

pre{"$and": [{"priority": "Low"},{"taskName": "Check email"}]}/pre

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

"edit js' code on where for query which takes input values for 2 variables and does collection lookup, then allows anoth

Hi,

Did you add JavaScript code on parameter 'where' mapping? If yes, there should be the following code:prereturn '{"$and": [{"incident_state":"' + Appery('report_input_state')&#46;val() + '"}, {"incident_county":"'+Appery('report_input_county')&#46;val()+'"}]}';/pre

kabrams
Posts: 0
Joined: Mon Nov 18, 2013 2:05 am

"edit js' code on where for query which takes input values for 2 variables and does collection lookup, then allows anoth

Thanks much, but that still doesn't work. I've got the return statement in my editjs 'where'. It's mapped to a local storage variable. My script above which calculates average runs on the success event of the query and nothing happens.

when i remove the 'where' js, it runs, but doesn't when I add code to the 'where' parameter. Any ideas?

Return to “Issues”