locked
Passing parameter to iframe RRS feed

  • Question

  • I need to pass a parameter from a CRM page to an iframe.  The parameter is an ID field which is not shown on screen but is in the database.  Can someone tell me how to do this?
    Wednesday, September 2, 2009 8:33 AM

Answers

  • Hi Mike,

    If it is the unique entity instance id that you want to get then you can use the ObjectId property of the form to get the value. 

    If it is another field then I recommend you use AJAX to retrieve the value. The post below demonstrates how to do that using fetchxml.
    http://mscrm4ever.blogspot.com/2008/09/ajax-using-fetch-message.html

    To pass the parameter to the Iframe you can pass it as a query string.
    The post on my blog demonstrates how to do that.


    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, September 2, 2009 8:56 AM

  • On the "Add an IFRAME -- webpage dialog" there is an option that you can check which automatically passes the objectid. 
    To enable this option please check the option "pass record object-type code and unique identifier as parameter." on the add iframe dialog page.

    Now using the code posted on my blog you can read the passed parameter using JavaScript. 

    OR 

    You can user the QueryString property of the HttpRequest object to read the parameter in c# or vb.net.

    You can find sample code at the url below.
    http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx


    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    • Proposed as answer by Hassan Hussain Wednesday, September 2, 2009 10:36 AM
    • Marked as answer by Donna EdwardsMVP Wednesday, September 9, 2009 8:05 PM
    Wednesday, September 2, 2009 10:36 AM

  • Please change your code to the line below.

    string strTest = Request.QueryString["id"].ToString();


    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, September 2, 2009 12:26 PM
  • Please debug the page. The error might not be at this line. The cause of the error might be something else.

    H.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, September 2, 2009 1:19 PM

All replies

  • Hi Mike,

    If it is the unique entity instance id that you want to get then you can use the ObjectId property of the form to get the value. 

    If it is another field then I recommend you use AJAX to retrieve the value. The post below demonstrates how to do that using fetchxml.
    http://mscrm4ever.blogspot.com/2008/09/ajax-using-fetch-message.html

    To pass the parameter to the Iframe you can pass it as a query string.
    The post on my blog demonstrates how to do that.


    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, September 2, 2009 8:56 AM
  • Hi
    On my blog there is examples for you to use
    Tiaan van Niekerk http://crmdelacreme.blogspot.com Skype:tiaan.van.niekerk1
    Wednesday, September 2, 2009 8:57 AM
  • It is the objectid that I need to pass.  Can you give me a code sample for doing this?
    Wednesday, September 2, 2009 9:40 AM
  • Hi Mike.

    Some thing along these lines should do it.

    var url = "http://servername/pagename.aspx";
    
    url = url + "&param=" + crmForm.ObjectId;
    
    crmForm.all.IFRAME_Name.src = url;
    

     

    Wednesday, September 2, 2009 10:29 AM

  • On the "Add an IFRAME -- webpage dialog" there is an option that you can check which automatically passes the objectid. 
    To enable this option please check the option "pass record object-type code and unique identifier as parameter." on the add iframe dialog page.

    Now using the code posted on my blog you can read the passed parameter using JavaScript. 

    OR 

    You can user the QueryString property of the HttpRequest object to read the parameter in c# or vb.net.

    You can find sample code at the url below.
    http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx


    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    • Proposed as answer by Hassan Hussain Wednesday, September 2, 2009 10:36 AM
    • Marked as answer by Donna EdwardsMVP Wednesday, September 9, 2009 8:05 PM
    Wednesday, September 2, 2009 10:36 AM
  • P Wain,

    Is this all the code I would need to put into my onload event?  Won't I need to declare crmForm somewhere as well?
    Wednesday, September 2, 2009 10:58 AM
  • Hassan,

    Your blog example is about passing values TO the CRM instead of FROM the CRM.
    Wednesday, September 2, 2009 11:00 AM
  • Mike,

     You dont need code to pass the ID to the Iframe. Check the "pass record object-type code and unique identifier as parameter."  option and MS CRM will pass the id to the page in the Iframe automatically.

    The code on the site explains how to read a querystring using JavaScript.

    The other link I posted below explains how you can read the querystring using c#.

    H.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, September 2, 2009 11:14 AM
  • I am trying to pass the ObjectID to an .aspx page and then capturing the value using the QueryString :

    string strTest = Request.QueryString["ObjectID"].ToString();

    But I get the error :

    Object reference not set to an instance of an object.

    What am I doing wrong here?
    Wednesday, September 2, 2009 11:21 AM

  • Please change your code to the line below.

    string strTest = Request.QueryString["id"].ToString();


    Hassan.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, September 2, 2009 12:26 PM
  • Hassan,

    string strTest = Request.QueryString["id"].ToString();

    gives me the same error.
    Wednesday, September 2, 2009 1:15 PM
  • Please debug the page. The error might not be at this line. The cause of the error might be something else.

    H.

    Hassan Hussain | http://hassanhussain.wordpress.com/
    Wednesday, September 2, 2009 1:19 PM