Question: I am working with Node, Angular & Mongo. And was able to successfully save and retrieve a user from the db. I have in my user model the following -> name: String. This is basically where the user inputs his first and last name.

Now i want to retrieve the name from the database and split the first and lastname up to retrieve the first letter of the first name and last name to create the initials of the user.

My question is how to do this basically:

Part of my app.js code for retrieving the user is the following (in this function I would write the split javascript code):

```
//Retrieving the users
        $scope.getUsers = function() {
            $http.get('/api/users').success(function(data) {
                    $scope.userInfo = data;

                    //console.log("Retrieved users from the server", data);
                    //$scope.linkTaskToUser(data);
                    //console.log(data);
                })
                .error(function(data, status, headers, config) {
                    console.log("Error in retrieving users from server");
                });

            var FirstLastName = $scope.userInfo.data.name;
            console.log('---->>>>>' , FirstLastName);

        }
        $scope.getUsers();

```

I tried something like this :

```
var FirstLastName = $scope.userInfo.data.name;
console.log('---->>>>>' , FirstLastName);

```

But of course this is not right (throws up an error)....

Answer: 
I don't think you need to be creating alias or such for this. You can also further utilise the criteria builder DSL to specify the restrictions. For example, 

```
def userList = UserRole.createCriteria().list(max: params.max,offset: params.offset){
  eq("role",Role.findByAuthority("ROLE_CANDIDATE"))
  user {
    ilike('username','%' + name + '%')
    if (userType == 1){
        eq("deleted", 1)
    } else if(userType == 2){
        eq("deleted", 0)
    }
  }
}*.user

```

The above appears to fall victim to a bug/feature of either Grails or Hibernate that causes failure if the table in question uses a composite key.. as UserRole (from the SpringSecurity plug) does.

An alternative is to use HQL - the equivalent of the above could be written as 

```
def userList = UserRole.executeQuery("select user from UserRole " +
            "where role_id = ? " +
            "and lower(username) like ? " +
            "and deleted = ?",[Role.findByAuthority("ROLE_CANDIDATE")?.id,
                               "%" + name.toLowerCase() + "%",
                               userType == 1 ? 1 : 0])

```

The first parameter to executeQuery is the query statement, the second parameter is a map containing the parameters to use in the query.
You are invoking the static methods on `Restrictions` that return expression instances which aren't used anywhere.

Invoke the instance methods (omit `Restrictions.`) so that they take effect in the `Criteria` being built.