Page 1 of 1

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

Posted: Tue Oct 20, 2015 6:18 pm
by Peter Perecz

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


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

Posted: Tue Oct 20, 2015 8:40 pm
by Serhii Kulibaba

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


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

Posted: Tue Oct 20, 2015 9:20 pm
by Peter Perecz

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


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

Posted: Wed Oct 21, 2015 5:22 pm
by Serhii Kulibaba

Please use JS below:

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


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

Posted: Thu Oct 22, 2015 8:35 pm
by Serhii Kulibaba

Please check this line:

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


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

Posted: Tue Oct 27, 2015 2:18 pm
by Peter Perecz

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


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

Posted: Fri Jul 17, 2020 2:20 pm
by Peter Perecz

Peter"