locked
get account id in onsave() RRS feed

  • Question

  • can u get the account id when i save the account in the on save event

    i mean i am creating a new account and when i click save i need to open the new custom webpage where i need to pass this account id
    Saturday, November 7, 2009 9:14 AM

Answers

  • When creating a new record, the accountid will not exist yet in the OnSave event. If the user clciks on Save (rather than Save and Close, or Save and New), then you can get the accountid in the subsequent onload event


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Saturday, November 7, 2009 1:14 PM
    Moderator
  • You should be able to call the save function in the onsave event of the form and then get the id with the crmForm.ObjectId and from there call your webpage..

    here are a few commands you can work with.

    //Force Form to save, in order to create GUID and re-load the form.
     crmForm.Save();         

     //Abort the original Save
     event.returnValue=false;
     return false;

    you might have to reload the form somewhere in between before getting the id, I don´t have access to CRM to test it and find the exact code for this but this should get you started.

    ##Added

    This should work for you.

    //Force Form to save, in order to create GUID and re-load the form.
     crmForm.Save();  

    /* Possibly some code to refresh the form to get the guid, there is if the crmForm.Save() does not do it, use alert(crmForm.ObjectId); to check if you have a guid after the crmForm.Save(); command */

    var guid = crmForm.ObjectId;

    /* Code to open the page with the guid */
    Monday, November 9, 2009 11:05 AM

All replies

  • When creating a new record, the accountid will not exist yet in the OnSave event. If the user clciks on Save (rather than Save and Close, or Save and New), then you can get the accountid in the subsequent onload event


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Saturday, November 7, 2009 1:14 PM
    Moderator
  • David is right. To get the account ID on the onLoad event, you just need to use this JavaScript code:  crmForm.ObjectId.


    Darren Liu | 刘嘉鸿 | MS CRM MVP | English Blog: http://msdynamicscrm-e.blogspot.com | Chinese Blog: http://liudarren.spaces.live.com
    Saturday, November 7, 2009 6:55 PM
    Moderator
  • Hi,

    You can use onload code crmForm.objectId to get account id, but to be able to get this id, fomr must be saved. But if user clicks save and close button,you can only get this id when form is opens another time.

    To resolve this, you can us anathor js code to disavle save and close button on forms which donot have object id, or cancel save and close event if you do not have object id, and manually use crmForm.Save() command to get what you need.

    return false, is what you nned to cancel form save.

    Ersin,


    Ersin Öztürk - TR
    Sunday, November 8, 2009 5:52 PM
  • Hi,

    You must be thinking to open "custom webpage" on some Custom button, so you can also create account record through JS(you can use SDK sample code to create record through JS ) that will return you new "account id" then you can open new web page.

    Hope it will help you !!!!
    Mahain
    Monday, November 9, 2009 6:03 AM
    Moderator
  • You should be able to call the save function in the onsave event of the form and then get the id with the crmForm.ObjectId and from there call your webpage..

    here are a few commands you can work with.

    //Force Form to save, in order to create GUID and re-load the form.
     crmForm.Save();         

     //Abort the original Save
     event.returnValue=false;
     return false;

    you might have to reload the form somewhere in between before getting the id, I don´t have access to CRM to test it and find the exact code for this but this should get you started.

    ##Added

    This should work for you.

    //Force Form to save, in order to create GUID and re-load the form.
     crmForm.Save();  

    /* Possibly some code to refresh the form to get the guid, there is if the crmForm.Save() does not do it, use alert(crmForm.ObjectId); to check if you have a guid after the crmForm.Save(); command */

    var guid = crmForm.ObjectId;

    /* Code to open the page with the guid */
    Monday, November 9, 2009 11:05 AM