Peter Perecz
Posts: 0
Joined: Sun Feb 01, 2015 9:02 pm

Save localstorage variable into database as a pointer field in Angular-Bootstrap

Hi There,

Could you pls help me with the next;

What I am trying to achieve in the Angular / Bootstrap builder is the following;

  • I use "Users" collection to store userIDs as normal

  • I have a local storage variable, in which I store the current userID (var currentuser = Apperyio.User.getUserId(); localStorage.setItem("currentuserlocal", JSON.stringify(currentuser));)

  • I have a collection for storing Organizations. In there I have a pointer field, which refers to the "Users" collection

  • I want to create a new record

    As a try if I set the scope with a discrete value it works perfectly;
    $scope.Org_to_Create.Org_Last_Modified_by_USERID = {"id":"562673f1e4b074527e208c3a","collName":"users"};

    But when I try with the local storage it does not add the record at all. I have tried the following variations. None of them works;

  • $scope.Org_to_Create.Org_Last_Modified_by_USERID = {"id":"'+currentuserlocal+'","collName":"users"};

  • $scope.Org_to_Create.Org_Last_Modified_by_USERID = {"collName":"users", "id":'+localStorage.getItem("currentuserlocal")+'}

    Could you please let me know the solution?

    Thanks,
    Peter

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Save localstorage variable into database as a pointer field in Angular-Bootstrap

Hello Peter,

Could you check are there any errors in console? This (http://devcenter.appery.io/documentat...) should help.

It is better to use $scope variables instead of localStorage

Peter Perecz
Posts: 0
Joined: Sun Feb 01, 2015 9:02 pm

Save localstorage variable into database as a pointer field in Angular-Bootstrap

Hello Sergiy,

This is what I see in Chrome Inspect Elements;
{"code":"DBSC205","description":"Collection '_users' doesn't contain object with id '+currentuserlocal+'."}

when I use this one;
$scope.Org_to_Create.Org_Last_Modified_by_USERID = {"collName":"users","id":"'+currentuserlocal+'"};

I have the same when I try it with $scope.variable;
$scope.userid = Apperyio.User.getUserId();
$scope.Org_to_Create.Org_Last_Modified_by_USERID = {"collName":"users","id":"'+$scope.userid+'"};

Failure in Chrome Inspect Elements;
{"code":"DBSC205","description":"Collection '_users' doesn't contain object with id '+$scope.userid+'."}

It seems there is an extra dot between ' and "" at the end but I have no clue where it is coming from.

Thanks,
Peter

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Save localstorage variable into database as a pointer field in Angular-Bootstrap

Please use JS below:

$scope.Org_to_Create.Org_Last_Modified_by_USERID = {"collName":"users","id":'"'+$scope.userid+'"'};

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Save localstorage variable into database as a pointer field in Angular-Bootstrap

Please check this line:

$scope.Org_to_Create.Org_Last_Modified_by_USERID = '{"collName":"users","id": "'+$scope.userid+'"}';

Peter Perecz
Posts: 0
Joined: Sun Feb 01, 2015 9:02 pm

Save localstorage variable into database as a pointer field in Angular-Bootstrap

Hello Sergiy,

Finally this one worked for me;

$scope.User_Details_to_Create.User_REF_ORG_ID.collName = "Organisations";
$scope.User_Details_to_Create.User_REF_ORG_ID._id = $scope.Created_Org_ID;

Thanks,
Peter

Return to “Issues”