How put data from http request to database and list

and the last question my master… how can i remove curly braces {} from all string of the json

ok please post the code you are using now and also the console log when you run it

Do this str = str.replace(/[{}]/g, “”);

Also check 2 things:

  1. Make sure that all the newObject values are strings “”, if any are integers then you can change the table key type from ‘text’ to ‘integer’ or can convert the integers to strings like so:

    caseTaskId: res.rows.item(i).caseTaskId.toString(),

  2. Make sure you delete the table: ‘Tabella_OdL’ before re-running the code as the ‘CREATE TABLE IF NOT EXISTS’ SQL command will not run if the table already exists.

If these don’t fix it post code and console logs here.

thank you…iìll try in few hours. Thank so much

the problem is that the app is a kind of agenda for manager, get data and show it as menu-master details.
For the details i need to make more http.get when inthe db there is the field stepName === “Approva/Rifiuta” i take the caseFolderId of the stepName, somthing like that
if(newObject.stepName === “Approva/Rifiuta”){
var casefolder = [];
casefolder = newObject.caseFolderId
http.get(‘http://demvsint-as1-sd.services.eni.intranet:8001/CaseManager/CASEREST/v1/case/’ + caseFolderId [i] + ?TargetObjectStore=CM_DCMSVS_TGT_OBJ
}

all this to update the second table of db and show in the last view the details
But for me is extremely difficult do this stuff

is the write to the database working now?

and post your code and explain what you want to do

the db give me the same error
Object {message: “sqlite3_step failure: UNIQUE constraint failed: Tabella_OdL.caseTaskId”, code: 0}
I modify the db with an _id primary key autoincrement.
But i can use the db, this error cause a huge slowdown but the db work.

The code is very huge…i’ll try to post all i can

var db = null;

var example = angular.module(‘starter’, [‘ionic’,‘ngCordova’, ‘starter.controllers’, ‘ngStorage’, ‘starter.services’])
.run(function($state,$timeout,$ionicPlatform, $cordovaSQLite, $ionicPopup, $cordovaNetwork,$cordovaDevice, $localStorage,$rootScope,$ionicSideMenuDelegate) {
$ionicPlatform.ready(function() {

db = $cordovaSQLite.openDB({name: “odl.db”, createFromLocation: 1});
console.log(db);
// console.log(SQLitePlugin);

    $cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS Tabella_OdL(_id INTEGER PRIMARY KEY AUTOINCREMENT, caseTaskId TEXT, caseFolderId TEXT, stepName TEXT, DV_Caseidentifier_for_eni_OdA TEXT, DV_EBELP_ODA TEXT, DV_EINDT_ODA TEXT,DV_NETPR_WAERS_POS_ODA TEXT, DV_MENGE_MEINS_POS_ODA TEXT, DV_MATNR_TXZ01_POS_ODA TEXT, DV_PEINH_POS TEXT, DV_NAMECL_POS_ODA TEXT)');

if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);

}
if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}

}
});
});

example.controller(“ExampleController”, function($ionicPlatform,Base64, $http, $ionicHistory,$ionicSideMenuDelegate, $ionicNavBarDelegate, $ionicGesture, $ionicLoading, $state, $ionicPopup, $stateParams, $location, Auth, $scope, $location, $rootScope, $cordovaSQLite, $localStorage,$timeout) {

$rootScope.risposta = [];
$rootScope.responseJSON=[];
$scope.newObject = [];
$rootScope.newObjectJSON = [];
var newObject = [];
$rootScope.allODL = [];
$scope.chiamataUno = function() {
/*
$ionicLoading.show({
content: ‘Loading’,
animation: ‘fade-in’,
showBackdrop: true,
maxWidth: 200,
showDelay: 0
});
*/
var authdata = Base64.encode(“DEMVSINT_ADMIN” + “:” + “Password01”);
$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);


    //new array non funge
    var newArray = [];
    $rootScope.newObjectJSON = []; 
    $scope.newObject = [];

    for(var i=0;i<response.queueElements.length;i++){
    var newObject = {
      //forse togliere elementi e columns 
      //elementi:response.queueElements[i],
      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("nuovo oggetto " + newObject);
    console.log("dettaglio " + newObject.DV_MENGE_MEINS_POS_ODA + " " + newObject.stepName + " " + newObject.DV_EINDT_ODA);

//anche qui ho tutto il JSON
$rootScope.newObjectJSON.push(JSON.stringify(newObject));
console.log(“rootScope.newObjectJSON " + $rootScope.newObjectJSON);
// $rootScope.newObjectJSON = JSON.stringify(newObject);
$rootScope.newObjectJSON = jsonString.replace(/(”{|}")/gi,’"’);

console.log("senza parentesi "+$rootScope.newObjectJSON);

//funziona ma da un errore
//Object {message: “sqlite3_step failure: UNIQUE constraint failed: Tabella_OdL.caseTaskId”, code: 0}
if($rootScope.newObjectJSON.length > 0) {
for(var i = 0; i < $rootScope.newObjectJSON.length;i++) {
var queryOdl = “INSERT INTO Tabella_OdL (_id,caseTaskId, caseFolderId, stepName, 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 (?,?,?,?,?,?,?,?,?,?,?,?)”;

        $cordovaSQLite.execute(db, queryOdl, [null,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]).then(function(result) {
          console.log("insert");
        }, function(error) {
          console.error(error);
        });

                //  $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");//mi da sempre lo stesso
    }
}else{
  console.log("nessun oggetto");
}

    
    }//fine for
    var queryB = "SELECT * FROM Tabella_OdL";
    $rootScope.allODL = [];
    $cordovaSQLite.execute(db, queryB, []).then(function(res) {
        if(res.rows.length > 0) {
           
            for(var i = 0; i < res.rows.length; i++) {
                 
               $rootScope.allODL.push({
                caseTaskId: res.rows.item(i).caseTaskId,
                caseFolderId: res.rows.item(i).caseFolderId,     
                stepName: res.rows.item(i).stepName,
                DV_Caseidentifier_for_eni_OdA: res.rows.item(i).DV_Caseidentifier_for_eni_OdA,
                DV_EBELP_ODA: res.rows.item(i).DV_EBELP_ODA,
                DV_EINDT_ODA: res.rows.item(i).DV_EINDT_ODA,
                DV_NETPR_WAERS_POS_ODA: res.rows.item(i).DV_NETPR_WAERS_POS_ODA,
                DV_MENGE_MEINS_POS_ODA: res.rows.item(i).DV_MENGE_MEINS_POS_ODA,
                DV_MATNR_TXZ01_POS_ODA: res.rows.item(i).DV_MATNR_TXZ01_POS_ODA,
                DV_PEINH_POS: res.rows.item(i).DV_PEINH_POS,
                DV_NAMECL_POS_ODA: res.rows.item(i).DV_NAMECL_POS_ODA,       
                });

              $rootScope.allODLJSON = JSON.stringify($rootScope.allODL);
             //console.log("json Tabella_OdL" + JSON.stringify($rootScope.allODL));
             $ionicLoading.hide();
            }
        } else {
            console.log("No results found ODL");
        }
       // $ionicLoading.hide();
    }, function (err) {
        console.error(err);
    });
        })
        .error(function(response) {
            alert("ERROR");
        });
}

end of the first http request…but I need to make other http request, if in the db there are fields stepName === “Approva/Rifiuta” i have to take the (multiple) casefolderid and insert this variable (array) in the url to make http request for all the casefolder(like a loop) and get the json data from the request…for example

(‘http://demvsint-as1-sd.services.eni.intranet:8001/CaseManager/CASEREST/v1/case/’ + caseFolderId [i] + ?TargetObjectStore=CM_DCMSVS_TGT_OBJ

after the first request getting all the data do you want to then immediately get extra data for all of the entries that have “Approva/Rifiuta” and save these into the database or do you only want to get this extra information when your manager clicks on a case and the database shows it has “Approva/Rifiuta”?

yes…I need to store all the data in 2 table at the login(so all request in the login). When click on the items of “Approva/Rifiuta” i need to show a first page a list with some details taken from the first table (first http request), when click on the item in the list,go in a third page and show the details of the second request(stored in the second table).
Thank you so much in advance

Is there always a “Approva/Rifiuta” column in the results?

Why not just forget the database. Load first list on app open, then when click on an item do a http call and get the approval/refuta http call? Much easier.

Otherwise you will have to check the database each time you add new data to see if the entry exists to avoid duplicating it. It’s a lot of extra work, only worth it if you need to access the data when there is no internet connection.

yes, this is the problem, i need data offline…anyway i’ll try to do my best.

HI, I now I need to get data from the cb, I need to get the casefolderId of all the rows Approva/rifiuta.
and put in an Array or arrayList… how can i do? the log say to me [object object]

var queryCF = “SELECT caseFolderId FROM Tabella_OdL WHERE stepName=‘Approva/Rifiuta’”;
$scope.allCF = [];
var arrayAllCF = [];
$cordovaSQLite.execute(db, queryCF, []).then(function(res) {
if(res.rows.length > 0) {

            for(var i = 0; i < res.rows.length; i++) {                    
               $scope.allCF.push(res.rows.item(i));

console.log("allCF " + $scope.allCF);
// $rootScope.allCFJSON = JSON.stringify($rootScope.allCF);
//console.log(“json arrayAllCF” + rootScope.allCFJSON);
//chiamata 2
}
} else {
console.log(“No CF found ODL”);
}
// $ionicLoading.hide();
}, function (err) {
console.error(err);
});