Select to view content in your preferred language

Trying to load Database values on StartUp

943
2
Jump to solution
08-07-2014 09:43 AM
KeithAnderson
Occasional Contributor

Folks

If you get a chance please point me the way on loading dynamic values into the app, on startup, from an external SQL Server db.

Effort in the txt file

Thanks

Keith

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JoshHevenor
Frequent Contributor

It looks like you're on the right track. I moved where you return your promise: 

function GetDatabaseValue(_newcity) {

                var def = new Deferred();

                var c = _newcity;

                var qTask = new QueryTask("http://localhost:6080/arcgis/rest/services/ggov_DatabaseValues/MapServer/2");

                var QT = new Query();

                QT.returnGeometry = false;

                QT.outFields = [

                    "CityName", "Html", "Picture", "Link", "Extent"

                ];

                QT.where = "CityName = '" + c + "'";

                qTask.execute(QT, function (results) {

                    //console.log(results);

                    var CityExtent;

                    var resultItems = [];

                    var resultCount = results.features.length;

                    for (var i = 0; i < resultCount; i++) {

                        var featureAttributes = results.features.attributes;

                        for (var attr in featureAttributes) {

                            if (attr == "Extent") {

                                CityExtent = featureAttributes[attr];

                                //console.info(CityExtent + " GetDatabaseValue");

                            }

                        }

                    }

                    def.resolve(CityExtent);

// REMOVE -->       return def.promise;

                }); //End of function results

                return def.promise;             // <------ ADD

            } // End Function GetDatabaseValue()

View solution in original post

0 Kudos
2 Replies
JoshHevenor
Frequent Contributor

It looks like you're on the right track. I moved where you return your promise: 

function GetDatabaseValue(_newcity) {

                var def = new Deferred();

                var c = _newcity;

                var qTask = new QueryTask("http://localhost:6080/arcgis/rest/services/ggov_DatabaseValues/MapServer/2");

                var QT = new Query();

                QT.returnGeometry = false;

                QT.outFields = [

                    "CityName", "Html", "Picture", "Link", "Extent"

                ];

                QT.where = "CityName = '" + c + "'";

                qTask.execute(QT, function (results) {

                    //console.log(results);

                    var CityExtent;

                    var resultItems = [];

                    var resultCount = results.features.length;

                    for (var i = 0; i < resultCount; i++) {

                        var featureAttributes = results.features.attributes;

                        for (var attr in featureAttributes) {

                            if (attr == "Extent") {

                                CityExtent = featureAttributes[attr];

                                //console.info(CityExtent + " GetDatabaseValue");

                            }

                        }

                    }

                    def.resolve(CityExtent);

// REMOVE -->       return def.promise;

                }); //End of function results

                return def.promise;             // <------ ADD

            } // End Function GetDatabaseValue()

0 Kudos
KeithAnderson
Occasional Contributor

Josh

Thank you good friend!

Keith

0 Kudos