locked
Guid of newly created record? RRS feed

  • Question

  • I'm trying to get the GUID of new account created but there is no values in the SaveChangesResultCollection:

    Account account = new Account();
    Account.name = "test";
    DbContext.Create(account);
    SaveChangesResultCollection results = DbContext.SaveChanges();
    How do I get the GUID for the newly created record?

    Tuesday, February 12, 2013 8:43 PM

Answers

  • Hi,

    You should use CreateRequest and CreateResponse objects to get the id of the newly created record. Here is an example of using these objects: 

    service.Execute(request);
    CreateRequest createRequest = new CreateRequest();
    createRequest.Target = target;
    CreateResponse resp = service.Execute(createRequest) as CreateResponse; // service is IOrganizationService
    Guid myId = resp.id

    • Marked as answer by DarinBrowne Tuesday, February 12, 2013 10:20 PM
    Tuesday, February 12, 2013 9:25 PM
  • try this may be help to you...

    Account account = new Account(); Account.name = "test"; guid accountid=DbContext.Create(account);


    ms crm

    • Marked as answer by DarinBrowne Wednesday, February 13, 2013 12:54 PM
    Wednesday, February 13, 2013 9:54 AM

All replies

  • Hi,

    You should use CreateRequest and CreateResponse objects to get the id of the newly created record. Here is an example of using these objects: 

    service.Execute(request);
    CreateRequest createRequest = new CreateRequest();
    createRequest.Target = target;
    CreateResponse resp = service.Execute(createRequest) as CreateResponse; // service is IOrganizationService
    Guid myId = resp.id

    • Marked as answer by DarinBrowne Tuesday, February 12, 2013 10:20 PM
    Tuesday, February 12, 2013 9:25 PM
  • Or you can use OrganizationServiceProxy.Create:

    http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.client.organizationserviceproxy.create.aspx

    It will return Guid of the newly created record.


    Alex Shlega, GotchaHunter.Net

    Tuesday, February 12, 2013 10:24 PM
  • try this may be help to you...

    Account account = new Account(); Account.name = "test"; guid accountid=DbContext.Create(account);


    ms crm

    • Marked as answer by DarinBrowne Wednesday, February 13, 2013 12:54 PM
    Wednesday, February 13, 2013 9:54 AM