CF9 ORM Grab id of latest created entity

Hi there

Am a bit stuck and wondered if anyone could assist

I am creating a new entity through the coldbox framework, so i have a
form which submits to the following handler

  void function save(event) output=false{
    var rc = event.getCollection();

    rc.user= taskService.getUser(event.getValue("iUserID",""));
    populateModel(rc.user);
    userService.save(rc.user);
  }

The userService.save method looks like this

  void function save(User user) output=false{
    transaction {
      entitySave(arguments.user);
    }
  }

What I would like to do, is drag the ID of the newly created user so I
can setNextEvent to that new users home page eg setNextEvent(users/
home/id=2)

Any ideas?

Many thanks

Just ask the object what its id is. It is populated on the object when
it is inserted.

Mark

Hi there, where would I ask the object what its id is? And how would I
do this?

Thanks

obj.getId()

Ok I am trying this as a test

        any function save(event) output=false{
                var rc = event.getCollection();

                rc.user= taskService.getUser(event.getValue
("iUserID",""));
                populateModel(rc.user);
                userService.save(rc.user);

               return rc.user;

        }

And I am seeing the newly created entitys details being returned as an
array, but the id field is empty for some reason.....any ideas why?
Thanks for your time

Update, sorry have managed to return the id field in the newly created
entity now...however when I now try this

    any function save(event) output=false{
                var rc = event.getCollection();

                rc.user= taskService.getUser(event.getValue
("iUserID",""));
                populateModel(rc.user);
                userService.save(rc.user);

               var id = rc.user.getId()

               return id ;

        }

I get the error message "Error casting an object of type
java.lang.Integer cannot be cast to java.lang.String to an
incompatible type."

Thanks

Ok, update again, ha ha

Managed to get it working...

Many thanks for your help