Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

How put data from http request to database and list

$
0
0

See my attempt to draw your attention to some errors below:

$scope.chiamataUno = function() {

var authdata = Base64.encode("xxx" + ":" + "xxx");

$http.defaults.headers.common["Authorization"] = "Basic " + authdata;

$http.get('http://demvsint-as1-sd.services.eni.intranet:8001/CaseManager/P8BPMREST/p8/bpm/v1/queues/DV_ResponsabileBSDL/workbaskets/Responsabile BSDL/queueelements/?cp=DCMSVS_CONN1')
.success(function(response) {

    console.log(response);

    $rootScope.risposta = response;

    $rootScope.responseJSON = JSON.stringify($scope.risposta);

    var newArray = [];

    $rootScope.newObjectJSON = [];

    $scope.newObject = [];

    for (var i = 0; i < response.queueElements.length; i++) {
       //missed var from newObject below
        var newObject = {
            caseFolderId: response.queueElements[i].caseFolderId,
            caseTaskId: response.queueElements[i].caseTaskId,
            stepName: response.queueElements[i].stepName,
            columns: response.queueElements[i].columns,
            DV_Caseidentifier_for_eni_OdA: response.queueElements[i].columns.DV_Caseidentifier_for_eni_OdA,
            DV_EBELP_ODA: response.queueElements[i].columns.DV_EBELP_ODA,
            DV_EINDT_ODA: response.queueElements[i].columns.DV_EINDT_ODA,
            DV_MATNR_TXZ01_POS_ODA: response.queueElements[i].columns.DV_MATNR_TXZ01_POS_ODA,
            DV_NAMECL_POS_ODA: response.queueElements[i].columns.DV_NAMECL_POS_ODA,
            DV_NETPR_WAERS_POS_ODA: response.queueElements[i].columns.DV_NETPR_WAERS_POS_ODA,
            DV_PEINH_POS: response.queueElements[i].columns.DV_PEINH_POS,
            DV_MENGE_MEINS_POS_ODA: response.queueElements[i].columns.DV_MENGE_MEINS_POS_ODA
        };

        newArray.push(newObject);

        console.log("dettaglio " + newObject.DV_MENGE_MEINS_POS_ODA + " " + newObject.stepName + " " + newObject.DV_EINDT_ODA);

// this gets changed everytime the loop runs so will end with the value from the last loop as rootscope is defined outside the scope of the function, push to an array if you want to retain all results in the loop, have changed it. See creation of array above.
$rootScope.newObjectJSON.push(JSON.stringify(newObject));
//$rootScope.newObjectJSON = JSON.stringify(newObject);

        if (newObject.length > 0) {
            for (var i = 0; i < newObject.length; i++) {
                var queryOdl = "INSERT INTO Tabella_OdL (caseTaskId, caseFolderId, DV_Caseidentifier_for_eni_OdA,DV_EBELP_ODA,DV_EINDT_ODA,DV_MATNR_TXZ01_POS_ODA,DV_NAMECL_POS_ODA,DV_NETPR_WAERS_POS_ODA,DV_PEINH_POS,DV_MENGE_MEINS_POS_ODA) VALUES (?,?,?,?,?,?,?,?,?,?) WHERE stepName = 'Item details'";
                $cordovaSQLite.execute(db, queryOdl, [newObject.caseFolderId, newObject.caseTaskId, newObject.stepName, newObject.DV_Caseidentifier_for_eni_OdA, newObject.DV_EBELP_ODA, newObject.DV_EINDT_ODA, newObject.DV_MATNR_TXZ01_POS_ODA, newObject.DV_NAMECL_POS_ODA, newObject.DV_NETPR_WAERS_POS_ODA, newObject.DV_PEINH_POS, newObject.DV_MENGE_MEINS_POS_ODA]);
                console.log("insert ODL");
            };
        } else {
            console.log("nessun oggetto");
        }

        // this gets changed everytime the loop runs so will end with the value from the last loop as $scope is defined outside the scope of the function, push to an array if you want to retain all results in the loop, have changed it.  See creation of array above.
        $scope.newObject.push(JSON.stringify(newObject));
        //$scope.newObject = newObject;

        // not sure what you are trying to do do here
        $rootScope.allODLJSON = JSON.stringify($scope.newObject);

        var allODLJSON = $rootScope.allODLJSON;
        console.log("json newObject" + allODLJSON);
    }
})
.error(function(response) {
    alert("ERROR");
});
}
//this is refering to multiple variables with this name which are specific to the previous function and as such are not accessable outside the function, this won't work
$scope.newObject = newObject;
$rootScope.allODLJSON = JSON.stringify($scope.newObject);

var allODLJSON = $rootScope.allODLJSON;
console.log("json newObject" + allODLJSON);

Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>