locked
how to get entity unique ID (key) when we create it by javascript? RRS feed

  • Question

  • Hello 

    after we clicked 'Save' ,'Save And Close' or 'Save and New'. 

    the entity was created, but how to get its KEY (entity unique ID) by javascript? 

    is is possible? 

     

    thanks in advance.

    Wednesday, March 2, 2011 10:41 AM

Answers

  • The Entity GUID identifier is available from within the Entity form using:

     

    crmForm.ObjectId
    

     

    But it is not available until AFTER the form has been Saved and subsequently re-opened.  If this is related to your efforts to make available a Form Upload control within an IFRAME, it will not work for a newly created entity instance, as there will be no way for the IFRAME to access the new GUID.

    It would be best to disable the IFRAME until after the entity instance has been created; re-enable only within an Update form.  For more see the SDK:

    http://msdn.microsoft.com/en-us/library/cc150873.aspx

     

     


    --pogo (pat)
    • Marked as answer by nevernet Thursday, March 3, 2011 1:33 AM
    Thursday, March 3, 2011 1:31 AM

All replies

  • Hello,

    I think what you are looking for is crmFormSubmit.crmFormSubmitId.DataValue.

    HTH,

    Oliver


    oliver barrera
    Wednesday, March 2, 2011 3:09 PM
  • Try var id = Xrm.Page.data.entity.getId();

    That will return the Id of the record, but you cannot put this in the onSave event script since it's fired before the record is created. Though, after the record is created and the window reloads, you can get the Id in the onLoad event script.

    If you really need it while creating - i suggest you put your logic in a plugin instead.

    /Emil

    Wednesday, March 2, 2011 3:14 PM
  • Thanks for your reply. 

    but Xrm (or  crm ,Crm ) doesn't defined. 

     

    i am using crm 4.0

    Thursday, March 3, 2011 1:24 AM
  • The Entity GUID identifier is available from within the Entity form using:

     

    crmForm.ObjectId
    

     

    But it is not available until AFTER the form has been Saved and subsequently re-opened.  If this is related to your efforts to make available a Form Upload control within an IFRAME, it will not work for a newly created entity instance, as there will be no way for the IFRAME to access the new GUID.

    It would be best to disable the IFRAME until after the entity instance has been created; re-enable only within an Update form.  For more see the SDK:

    http://msdn.microsoft.com/en-us/library/cc150873.aspx

     

     


    --pogo (pat)
    • Marked as answer by nevernet Thursday, March 3, 2011 1:33 AM
    Thursday, March 3, 2011 1:31 AM
  • Thanks,

    but after i called crmForm.Save(). 

    your code "crmFormSubmit.crmFormSubmitId.DataValue" doesn't work too. 

    it's undefined.

     

    Thanks,

    Thursday, March 3, 2011 1:32 AM
  • Hello pogo69

     

    nice to meet you again :)

    i did what you are said. 

     

    thanks again.

    Thursday, March 3, 2011 1:33 AM
  • My apologies.  Please use 'crmFormSubmit.crmFormSubmitId.value' instead.

    Good Luck!

    Oliver


    oliver barrera
    Thursday, March 3, 2011 1:51 AM
  • doesn't matter, 

    but i cannot get its value

    see my code:

      $('#_MBcrmFormSave').click(function() {
        if (crmForm.FormType == 1) {
          var a = crmForm.Save();
          if (a == false) return a;
    
          try {
            console.log(crmFormSubmit.crmFormSubmitId.value);
          } catch (e) { alert(e); }
        } 
      });
    

    Thursday, March 3, 2011 2:07 AM