Where to Get New Record Id

2 posts, 0 answers
  1. Kelly
    Kelly avatar
    73 posts
    Member since:
    Apr 2011

    Posted 24 Feb 2014 Link to this post


    I'm working on a scheme where one user can add a record to a TBS content type, and assign ownership of that record to a different user.  Using the .net sdk, I tried to set the owner and/or ACL in the request, but found that they are ignored.  Rather than make two round trips, I decided to move the reassignment of ownership into the cloud code, like this:

    Everlive.Events.afterCreate(function(request, response, context, done) {
          var id = request.data._id;
          var owner = request.data.NewOwner;
          Everlive.Sdk.withMasterKey().data('Blah').setOwner(owner, id);
          console.log("Changed " + id + " owner to " + owner);

    This actually works, but I don't like the looks of that request.data._id field.  That's the only place I could see the record Id of the new record in the console log.  It seems as though the new record id should be somewhere inside the response, not the request, no?  I can't find documentation describing the cloud code arguments, so can you please tell me the best way to do this?  Also, why is specifying the owner or ACL when creating a record disallowed? (or am I just doing it incorrectly...?)

    Thank you,

  2. Anton Dobrev
    Anton Dobrev avatar
    531 posts

    Posted 25 Feb 2014 Link to this post

    Hi Kelly,

    To set the owner of an item client-side, the request must be authenticated with the credentials of the current owner of the item or with a master key. Otherwise, the request will fail (with 'Not found' error) because the current user cannot access the item permissions. Also, keep in mind the general security prescription to not deploy the master key with your app.

    We'd suggest that such custom logic resides in the cloud code. You can access the Id of the created item in the response.result object like in the following snippet:
    Everlive.Events.afterCreate(function(request, response, context, done) {
         var createdItemId = response.result.Id;
        var ownerId = 'GUID-here';
        Everlive.Sdk.withMasterKey().data('MyContent').setOwner(ownerId, createdItemId);

    Let us know if this works for you.

    Anton Dobrev
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
Back to Top