locked
Migrating to 2013 (need a little help with code) RRS feed

  • Question

  • Hi

    In VS2012 Ultimate, I have the following JavaScript code in a project:

    //myapp.ViewStoreGroup.addDynamicSurvey_execute = function (screen) {
    //    var newSurvey = new myapp.Survey();
    //    newSurvey.setStore(screen.GroupList.selectedItem.Store);
    // Save all changes on the screen
    //    screen.showTab("StartedSurveys");
    //    return myapp.activeDataWorkspace.ApplicationData
    //        .saveChanges().then(function () {
    //            screen.showTab("StartedSurveys");
    //        })
    //};
    
    // Replace the code below with the code above when you migrate to VS 2013 and remove the button
    myapp.ViewStoreGroup.addDynamicSurvey_execute = function (screen) {
        var newSurvey = new myapp.Survey();
        newSurvey.setStore(screen.GroupList.selectedItem.Store);
        newSurvey.Status = "Started";
        newSurvey.SurveyDateCreated = new Date();
        newSurvey.StoreName = screen.GroupList.selectedItem.Store.Name;
        newSurvey.StoreName = screen.GroupList.selectedItem.Store.Chain.Name;
        // Get the location of a device
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (pos) {
                newSurvey.Latitude = pos.coords.latitude.toString();
                newSurvey.Longitude = pos.coords.longitude.toString();
            });
        }
        else {
            alert("Geolocation not supported");
        }
        return myapp.activeDataWorkspace.ApplicationData
        then.saveChanges()
        //   /\
        //   ||
        // Remove this "then" word when you migrate to VS 2013
        // Save all changes on the screen
        // NOTE: Remove comments when migrating to VS 2013
        //    screen.showTab("StartedSurveys");
    
        //        .then(function () {
        //            screen.showTab("StartedSurveys");
        //        })
    };

    The above correctly inserts the Long/Lat into the new record.

    I applied the commented changes above but somehow after upgrading the project to VS2013 Ultimate Preview, I have caused all fields except the Long/Lat are empty.

    Below is the new code. Please assist. Many thanks, Mark.

    myapp.ViewStoreGroup.addDynamicSurvey2_execute = function (screen) {
        var newSurvey = new myapp.Survey();
        newSurvey.setStore(screen.GroupList.selectedItem.Store);
        newSurvey.Status = "Started";
        newSurvey.SurveyDateCreated = new Date();
        newSurvey.StoreName = screen.GroupList.selectedItem.Store.Name;
        newSurvey.StoreName = screen.GroupList.selectedItem.Store.Chain.Name;
        // Get the location of a device
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (pos) {
                newSurvey.Latitude = pos.coords.latitude.toString();
                newSurvey.Longitude = pos.coords.longitude.toString();
                alert(newSurvey.Longitude);
            });
        }
        else {
            alert("Geolocation not supported");
        }
        // Save all changes on the screen
    
        return myapp.activeDataWorkspace.ApplicationData
        .saveChanges()
        .then(function () {
              screen.showTab("StartedSurveys");
       })
    };


    Mark

    Monday, July 29, 2013 8:31 AM