Embedding a Linked Web Page in CRM

This blog shows how a linked web page can be embedded into a Microsoft CRM Form using an iFrame.
Information from the page is passed to the underlying .aspx application via parameters embedded in the URL.

The purpose of this example is to link to another system and extract and display related information in the form. It is assumed that the Id for the other system needs identified in the CRM and this has been added as a field called CRMId. Alternatively you could use the CRM GUID and create the relationship within the other system.

CRM Form

  • First create an iFrame in the form which has the URL of the .aspx page to which you want to link.

iFrameProps

Note that ‘Restrict cross-frame scripting’ is disabled.
This is necessary to stop the scripting in the page being disabled.
  • Then add a field which I have called CRM Id (xxx_crmid) as the Id for the related system.
  • Click on form properties and add a new library and function as shown below.

function Create_URL_and_Parameters()

{
var params = “”;
var Id= Xrm.Page.getAttribute(“xxx_crmid”).getValue();

//Set the Parameters to be used by the .aspx page in the iFrame
params= params+ “?Id=” + Id ;

//get the existing URL from the iFrame
var IFrame = Xrm.Page.ui.controls.get(“IFRAME_Test_iFrame”);
var URL= IFrame.getSrc();

//Append the parameters to the URL
URL= URL+ params;

// Use the setSrc method so that the IFRAME uses the page parameters
IFrame.setSrc(URL);
}

Form Properties

 

Web Application

In Visual Studio do the following

  • Create a new web application.
  • Add and configure a data source to the data to which you want to link e.g. a table in SQL Server e.g. SqlDataSource1
  • Add a Label e.g. Label1
  • Add a grid to display the data e.g. GridView1
  • Select the data source and add an ‘Init’ event (SqlDataSource1_Init)
  • Add code as per the example below…

protected void SqlDataSource1_Init(object sender, EventArgs e)
{

int x = 0;

//Confirm the Id is valid i.e. that it is not null and is an integer

if (Request.QueryString[“Id”] != null && Int32.TryParse(Request.QueryString[“Id”], out x))
{

//Set the Label to the Id value from CRM
Label1.Text = “Id: ” + Request.QueryString[“Id”];

//Set the select string WHERE clause to the CRM Id value from the Query string
SqlDataSource1.SelectCommand = “SELECT [Id], [CRMId], [Name], [Information], [Value] FROM [CRM Data] WHERE CRMId = ” + Int32.Parse(Request.QueryString[“Id”]);

}

else
{

//Clear the Select command if there is no matching data – we do not want to show anything
SqlDataSource1.SelectCommand = “”;

}

}

Notes:

By setting the data source at the initialise stage the data source queries using the parameter that has been provided from the CRM page.
You could do the same using the select query and parameter but that is troublesome to get working.

Sample Data

Sample data

 

 Finished Result…

CRM Id is set to 1235

CRM Id field

This results in only records with the CRM Id of 1234 are displayed in the web page.
This effectively links the data between the two systems.

Output

Leave a Reply

Your email address will not be published. Required fields are marked *