
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 09:14 AM
I'm trying to create a widget which displays a users information. I'm calling both the User Table and my custom 'members table' which references many of the fields within the user table. When a user clicks the delete button I want the record from the members table to be deleted and when the update button is pressed I want the User table to be updated. This isn't my issue though. My issue is that when I use the server.update() method it updates and then deletes the record no matter which button is pressed. I understand why it's not working but not how to fix it. How can I separate the calls to the server?
Here's my client and server side code:
$scope.deleteUser = function() {
$scope.server.update();
}
$scope.updateUser = function() {
$scope.server.update();
}
================================
if(this.input) {
memberRecord.deleteRecord();
}
if(this.input) {
userRecord.first_name = this.input.user.firstName.toString();
userRecord.last_name = this.input.user.lastName.toString();
userRecord.email = this.input.user.email.toString();
userRecord.roles = this.input.user.roles.toString();
userRecord.update();
data.user = this.input.user;
gs.addInfoMessage('Update Successful');
}
Thanks,
Dylan
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 09:28 AM
One way to do this would be to add an action variable into your input object.
Set $scope.data.action to update or delete when the respective button is pressed, then on the server say if(input.action =="delete")... and so on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 09:19 AM
c.server.update().then(function(){
//Give your inputs here and it should solve your issue.
})
PS: Hit like, Helpful or Correct depending on the impact of the response
Thanks,
Ajay Limaye
Solugenix Corporation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 09:28 AM
One way to do this would be to add an action variable into your input object.
Set $scope.data.action to update or delete when the respective button is pressed, then on the server say if(input.action =="delete")... and so on.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 11:02 AM
What if the input object is all on the server side? I have a data.user on the server side which the html references in the ng-models. Am I adding an action field to that user object and trying to change it before the update?
Like so:
server side:
data.user = {
firstName: userRecord.first_name.toString(),
lastName: userRecord.last_name.toString(),
email: userRecord.email.toString(),
roles: userRecord.roles.toString(),
action: ''"
};
client side:
$scope.deleteUser = function() {
$scope.data.action = 'delete';
$scope.server.update();
}
$scope.updateUser = function() {
$scope.data.action = 'update';
$scope.server.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 11:32 AM
You don't have to add it to the user object necessarily. You can if that's what you want to do but it isn't necessary. If you do, just change $scope.data.action to $scope.data.user.action in the controller.
Any changes you make to $scope.data should be copied to the input object when you call back to the server via server.update() or similar.
So, you should be able to set $scope.data.action like you are in the ng-click function for your button and then just have an if condition on the server checking what the value of input.action is.
I did this on a widget once and it went something like this:
// Client Controller
c.update = function(){
...
c.data.action = 'update';
c.server.update();
};
c.delete = function(){
...
c.data.action = 'delete';
c.server.update();
};
// Server script
if(input && input.action =='update' ){
... do your update stuff here ...
}
if(input && input.action =='delete' ){
... do your delete stuff here ...
}