locked
How to pass the context objectID to ISV MenuBar Button RRS feed

  • Question

  • I have a requirement where I need to be able to open a custom webpage using some data from the Grid MenuBar and ObjectID . I have placed the button on the Grid Menubar with the following code. I am able to retrieve the grid selected rows but not sure how to pass/get the EntityID by clicking on the GridView button.

    My code looks as below... The ?? icon shows the issue point.

    <Grid>
                <MenuBar>
                  <Buttons>
                    <Button Icon="/_imgs/ico_18_mappings.gif" JavaScript="window.showModalDialog('/ISV/myApp/myCustomPage.aspx?ObjectId=' + ?? + '&SelectedRows=' + getSelected('crmGrid'), null, 'dialogHeight=400px,dialogWidth=300px,status=no,toolbar=no,menubar=no,location=no'); crmGrid.Refresh();" WinParams="" PassParams="1">
                      <Titles>
                        <Title LCID="1033" Text="View" />
                      </Titles>
                      <ToolTips>
                        <ToolTip LCID="1033" Text="View the selected Record" />
                      </ToolTips>
                    </Button>
                  </Buttons>
                </MenuBar>
              </Grid>

    Please let me know if anyone has any ideas.

    • Edited by SP22403 Monday, September 13, 2010 3:33 PM
    Monday, September 13, 2010 3:13 PM

Answers

  • Ok,

    you can get this using window.opner

    Check this http://msdn.microsoft.com/en-us/library/cc150863.aspx

     


    Mahain : http://mahenderpal.wordpress.com
    • Proposed as answer by HIMBAPModerator Monday, September 13, 2010 3:39 PM
    • Marked as answer by SP22403 Monday, September 13, 2010 7:16 PM
    Monday, September 13, 2010 3:38 PM
    Moderator
  • Hi.

    Try to use window.parent.crmForm.ObjectId.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Monday, September 13, 2010 4:44 PM
    Moderator
  • Hi

    Since your button is on an IFrame, so as to access the parent forms object id you need to use parent.window.crmForm.ObjectId. if the button is on the parent form then it is crmForm.ObjectId.

    I guess what you want here is to pass the guid of the select grid row rather than parent forms ObjectId. Also you have to encode & => &amp;

    here is the code

    <Grid>
                <MenuBar>
                  <Buttons>
                    <Button Icon="/_imgs/ico_18_mappings.gif" JavaScript="var objectID =window.parent.crmForm.ObjectId ; window.showModalDialog('/ISV/myApp/myCustomPage.aspx?ObjectId=' +escape( objectID ) + '&amp; SelectedRows=' + getSelected('crmGrid'), null, 'dialogHeight=400px,dialogWidth=300px,status=no,toolbar=no,menubar=no,location=no'); crmGrid.Refresh();" WinParams="" PassParams="1">
                      <Titles>
                        <Title LCID="1033" Text="View" />
                      </Titles>
                      <ToolTips>
                        <ToolTip LCID="1033" Text="View the selected Record" />
                      </ToolTips>
                    </Button>
                  </Buttons>
                </MenuBar>
              </Grid>

     


    Hope this helps. Amar
    • Marked as answer by SP22403 Tuesday, September 14, 2010 2:16 PM
    Monday, September 13, 2010 7:40 PM
  • Hi, I could not find any tool download link in the Url you mentioned above. Also, I am not sure if the above ISVConfig code that is not working above is a CRM ISVConfig compliance issue or XML Standard issue.

    Please help.


    Hi.

    Try this - http://cid-23a519594c2cb8c5.office.live.com/self.aspx/BLOG%20CRMTOOLS%20FILES/XmlValidator.zip


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by SP22403 Tuesday, September 14, 2010 2:13 PM
    Tuesday, September 14, 2010 1:05 PM
    Moderator
  •  

    Hi

    I have just checked this code and it works fine without getSelected('crmGrid'). I'm able to read the objectId of the parent form and should be the same case at your end. Only thing I would suggest is to check your getSelected functions return value and that it is loaded and available for the script to execute.

    <Button Icon="/_imgs/ico_18_mappings.gif" JavaScript="var objectID=window.parent.crmForm.ObjectId;window.showModalDialog('/ISV/myApp/myCustomPage.aspx?ObjectId='+escape( objectID )+'&amp;SelectedRows=' + getSelected('crmGrid'), null, 'dialogHeight=400px,dialogWidth=00px,status=no,toolbar=no,menubar=no,location=no');" WinParams="" PassParams="1">


    Hope this helps. Amar
    • Proposed as answer by Faisal Fiaz Tuesday, September 14, 2010 1:37 PM
    • Marked as answer by SP22403 Tuesday, September 14, 2010 2:13 PM
    Tuesday, September 14, 2010 1:36 PM

All replies

  • try crmform.ObjectTypeCode
    Mahain : http://mahenderpal.wordpress.com
    Monday, September 13, 2010 3:23 PM
    Moderator
  • Hi, actually I dont need the objecttypecode, instead I want the objectid of the current document.

    For example, when I open a account entity and navigate to the opportunity grid, upon clicking the above button on the opportunity grid, I want to be able to pass the currently open account entity's id in there.

    Monday, September 13, 2010 3:30 PM
  • Ok,

    you can get this using window.opner

    Check this http://msdn.microsoft.com/en-us/library/cc150863.aspx

     


    Mahain : http://mahenderpal.wordpress.com
    • Proposed as answer by HIMBAPModerator Monday, September 13, 2010 3:39 PM
    • Marked as answer by SP22403 Monday, September 13, 2010 7:16 PM
    Monday, September 13, 2010 3:38 PM
    Moderator
  • Hi.

    Try to use window.parent.crmForm.ObjectId.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Monday, September 13, 2010 4:44 PM
    Moderator
  • Hi

    Since your button is on an IFrame, so as to access the parent forms object id you need to use parent.window.crmForm.ObjectId. if the button is on the parent form then it is crmForm.ObjectId.

    I guess what you want here is to pass the guid of the select grid row rather than parent forms ObjectId. Also you have to encode & => &amp;

    here is the code

    <Grid>
                <MenuBar>
                  <Buttons>
                    <Button Icon="/_imgs/ico_18_mappings.gif" JavaScript="var objectID =window.parent.crmForm.ObjectId ; window.showModalDialog('/ISV/myApp/myCustomPage.aspx?ObjectId=' +escape( objectID ) + '&amp; SelectedRows=' + getSelected('crmGrid'), null, 'dialogHeight=400px,dialogWidth=300px,status=no,toolbar=no,menubar=no,location=no'); crmGrid.Refresh();" WinParams="" PassParams="1">
                      <Titles>
                        <Title LCID="1033" Text="View" />
                      </Titles>
                      <ToolTips>
                        <ToolTip LCID="1033" Text="View the selected Record" />
                      </ToolTips>
                    </Button>
                  </Buttons>
                </MenuBar>
              </Grid>

     


    Hope this helps. Amar
    • Marked as answer by SP22403 Tuesday, September 14, 2010 2:16 PM
    Monday, September 13, 2010 7:40 PM
  • Hi, Thanks for all the inputs. I am now using the code specified as below, but getting some weird issue with the ISVCoinfig.

     

    I tried the following line of code... the Import Customization process finds this invalid and does not allow for import.

    <Button Icon="/_imgs/ico_18_mappings.gif" JavaScript="var objectID =window.parent.crmForm.ObjectId ; window.showModalDialog('/ISV/myApp/myCustomPage.aspx?ObjectId=' +escape( objectID ) + '&amp; SelectedRows=' + getSelected('crmGrid'), null, 'dialogHeight=400px,dialogWidth=300px,status=yes,toolbar=yes,menubar=yes,location=yes'); crmGrid.Refresh();" WinParams="" PassParams="1">

     

    I tried to tweak the code with the following to make it ISVCOnfig compliant... please notice the difference in BOLD.

    <Button Url="Javascript{ var objectID =window.parent.crmForm.ObjectId;
                window.showModalDialog('/ISV/myApp/myCustomPage.aspx?ObjectId='+escape(objectID) +'&amp;SelectedRows=' + getSelected('crmGrid'), null,'dialogHeight=400px,dialogWidth=300px,status=yes,toolbar=yes,menubar=yes,location=yes'); }"
            WinParams="" PassParams="1">

    The above code was now importable but does not work as intended. It spits the following value in the addressbar of the new window.

    http://localhost:5555/MYORG/_root/Javascript%20%20%20%7Bvar%20objectID%20=window.parent.crmForm.ObjectId;%20%20%20%20window.showModalDialog('/ISV/myApp/myCustomPage.aspx?id='+escape(objectID), null,'dialogHeight=400px,dialogWidth=600px,status=yes,toolbar=yes,menubar=yes,location=yes');} &orgname=MYORG&userlcid=1033&orglcid=1033

    Can someone please help?

    Tuesday, September 14, 2010 2:19 AM
  • Hi.

    It seems that you have an error inside your customization file. Try to use Xml Validation tool to validate your customization file.
    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Tuesday, September 14, 2010 9:45 AM
    Moderator
  • Hi, I could not find any tool download link in the Url you mentioned above. Also, I am not sure if the above ISVConfig code that is not working above is a CRM ISVConfig compliance issue or XML Standard issue.

    Please help.
    Tuesday, September 14, 2010 1:00 PM
  • Hi, I could not find any tool download link in the Url you mentioned above. Also, I am not sure if the above ISVConfig code that is not working above is a CRM ISVConfig compliance issue or XML Standard issue.

    Please help.


    Hi.

    Try this - http://cid-23a519594c2cb8c5.office.live.com/self.aspx/BLOG%20CRMTOOLS%20FILES/XmlValidator.zip


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by SP22403 Tuesday, September 14, 2010 2:13 PM
    Tuesday, September 14, 2010 1:05 PM
    Moderator
  •  

    Hi

    I have just checked this code and it works fine without getSelected('crmGrid'). I'm able to read the objectId of the parent form and should be the same case at your end. Only thing I would suggest is to check your getSelected functions return value and that it is loaded and available for the script to execute.

    <Button Icon="/_imgs/ico_18_mappings.gif" JavaScript="var objectID=window.parent.crmForm.ObjectId;window.showModalDialog('/ISV/myApp/myCustomPage.aspx?ObjectId='+escape( objectID )+'&amp;SelectedRows=' + getSelected('crmGrid'), null, 'dialogHeight=400px,dialogWidth=00px,status=no,toolbar=no,menubar=no,location=no');" WinParams="" PassParams="1">


    Hope this helps. Amar
    • Proposed as answer by Faisal Fiaz Tuesday, September 14, 2010 1:37 PM
    • Marked as answer by SP22403 Tuesday, September 14, 2010 2:13 PM
    Tuesday, September 14, 2010 1:36 PM
  • Thank you folks. I made some single quote mistake in the URL...finally able to get it to work.

    <Button JavaScript="if (window.parent.crmForm != undefined)
        {var sUrl = '/ISV/myApps/myCustomPage.aspx?id=' +
        window.parent.crmForm.ObjectId +'&amp;orgname=' + ORG_UNIQUE_NAME +';} else {var sUrl =
        '/ISV/myApps/myCustomPage.aspx';};
        window.open(sUrl, null, 'menubar=0, status=1, toolbar=1, location=1, resizable=1');">

     

    Tuesday, September 14, 2010 2:15 PM