locked
Get current record ID using javascript RRS feed

  • Question

  • Hi all,

    I have a requirement where I need to simulate the behavior of close opportunity button so that it can be displayed for specific users.

    So I have created a similar dialog and I have customized the ribbon to display the button and added a javascript function to call the dialog.

    Everything is going fine as long as I am inside the opportunity form.

    I have tried to add the same button on the opportunity homepage grid so I can call the dialog without opening the form and here is the errror.

    My code depend on:

    Xrm.Page.data.entity.getEntityName();
    
    Xrm.Page.data.entity.getId();

    So I can get the record id and the entity name that I work on

    So I was looking for way to get the record ID without using Xrm.Page.data as they cannot be used outside the form

     

     

    Thanks and best regards...


    Sunday, January 1, 2012 11:42 AM

Answers

  • hi mostafa

    follow this link


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, January 2, 2012 9:21 AM

All replies

  • Any suggestions ??
    Sunday, January 1, 2012 2:31 PM
  • Hello, any updates about my problem ??
    Sunday, January 1, 2012 11:28 PM
  • Hi Mostafa,

                    Did you include a CrmParameter inside the Javascript function definition in the RibbonDiffXml, there is a value you can use to get the Ids, use CrmParameter PrimaryItemIds to get all the Ids of the selected records in the home grid or FirstPrimaryItemId to only que get the first one.


    Regards,
    Damian Sinay
    Monday, January 2, 2012 2:29 AM
  • HI,

    Pass your id as query string and access or you can try opener.Xrm or Parent.Xrm.Page.

     

     


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, January 2, 2012 5:06 AM
  • Dear Damian,

    Would you please provide code samples or links that describe what you mention

    Monday, January 2, 2012 9:08 AM
  • hi mostafa

    follow this link


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, January 2, 2012 9:21 AM
  • thanks alot :)

    but this makes me wondering if there is any way to pass more than one paremeter using CrmParameter ??

    Monday, January 2, 2012 1:56 PM
  • sure, you can add more than one CrmParameter node inside the JavaScriptFunction node
    Regards,
    Damian Sinay
    Monday, January 2, 2012 3:31 PM
  • Hii mostafa you can add different parameters,

     

     

    <JavaScriptFunction 
     FunctionName="String"
     Library="String" >
     <BoolParameter/>
     <CrmParameter />
     <DecimalParameter/>
     <IntParameter/>
     <StringParameter/>
    </JavaScriptFunction>


    By Sanz If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Monday, January 2, 2012 3:44 PM