graphics undefined even after update-end fires.

Discussion created by broadstreet on Jun 17, 2014
Latest reply on Jun 17, 2014 by broadstreet
So i've been learning the Javascript API and i've been building a custom page based on several samples. What i'm finding is that I'm obviously not understanding a concept here and it's causing me some problems. The following is a code snip from the page i'm building the entire source can be found at a link at the bottom posted to paste bin.
    var map;
    var currPoint;
            "dijit/form/TextBox", // this we only include to make an example with TextBox
            "dojo/domReady!"], function (Map, arcgisUtils, Legend, Graphic, SimpleLineSymbol, SimpleMarkerSymbol, SimleRenderer,
                                         SimpleFillSymbol, Color, FeatureLayer, Circle, OpenStreetMapLayer, esriRequest, GeometryService,
                                         dom, parser, all,array, HorizontalSlider, HorizontalRule,
                                         HorizontalRuleLabels, TextBox, domConstruct, on, esriConfig) {
                var geometryService,baseGraphics;
                // = "/proxy";
                // = false;
                map = new esri.Map("mapDiv", {
                    center: [-114.0288, 51.0669],
                    zoom: 10

                var osmLayer = new OpenStreetMapLayer({

                geometryService = new GeometryService("");

                var legend = new Legend({
                    map: map,
                    layerInfos: (arcgisUtils.getLegendLayers(map))
                }, "legendDiv");

                var rulesNode = domConstruct.create("div", {}, dom.byId("slider"), "first");
                var sliderRules = new HorizontalRule({
                    container: "topDecoration",
                    count: 6,
                    style: "width: 5px;"
                }, rulesNode);

                // Create the labels
                var labelsNode = domConstruct.create("div", {}, dom.byId("slider"), "first");
                var sliderLabels = new HorizontalRuleLabels({
                    container: "topDecoration",
                    labelStyle: "font-style: italic; font-size: 0.75em",
                    count: 6,
                    labels: [5, 10, 15, 20, 25, 30]
                }, labelsNode);

                var slider = new HorizontalSlider({
                    name: "slider",
                    value: 5,
                    minimum: 5,
                    maximum: 30,
                    intermediateChanges: true,
                    discreteValues: 6,

                    style: "width:300px;",
                    onChange: function (value) {
                        dom.byId("sliderValue").value = value;
                }, "slider");

                var siteValue = dom.byId('drpSite').value;
                var drpSite = dom.byId("drpSite");
                on(drpSite, "change", function (e) {
                    siteValue = dom.byId('drpSite').value;
                var sites = new FeatureLayer("", {
                    mode: FeatureLayer.MODE_ONDEMAND,
                    id: "CalgarySites",
                    name: "Calgary Sites",
                    outFields: ["*"]
                var dt = new FeatureLayer("", {
                    mode: FeatureLayer.MODE_ONDEMAND,
                    id: "DriveTime",
                    name: "Drive Times",

                sites.setDefinitionExpression("NICKNAME='" + siteValue + "'");
                sites.on("update-end", function (evt) {
                    currPoint = new Graphic([0].toJson());
                    dt.setDefinitionExpression("NICKNAME='" + siteValue + "' and ToBreak=" + sliderValue.value);

                dt.on("update-end", function (evt) {
                    var promises = new all({
                        poilist : executeLocalSearch(currPoint)


                function buildMap() {
                    sites.setDefinitionExpression("NICKNAME='" + siteValue + "'");

The error I'm getting is the one listed here.
TypeError: Unable to draw graphic (null):[0] is undefined
currPoint = new Graphic([0].toJson());

my assumption was that when i first getting the error it had to do with the asynchronous nature of the code so i switched to using the update-end on the point layer (sites) figuring that once the update-end fired i should have a graphic with a point. However, the error above seems to imply differently. Any suggestions or help is much appreciated.

full code available here.