Pass Custom Parameters to The HTML Web Resource through Iframe -XRM2011

Pass Custom Parameters to The HTML Web Resource through Iframe -XRM2011

Pass XRM Form Data to the web resource as Custom Parameters as follows:

function SendCustomUrlToIframe(ifarmeUrl, iFrame) {

 var customerId =;

 if (customerId != null) 
  Xrm.Page.getControl(iFrame).setSrc(ifarmeUrl + "&id=" + customerId); 

Another Example:

The following sample shows you how to set the src property for the IFRAME and any parameters by using the onChange event of an option set field.

//Get the value of an option set attribute
var value ="new_pagechooser").getValue();
var newTarget = "";
//Set the target based on the value of the option set
switch (value) {
    case 100000001:
        newTarget = "http://myServer/test/pageOne.aspx";
        newTarget = "http://myServer/test/pageTwo.aspx";
//Get the default URL for the IFRAME, which includes the 
// query string parameters
var IFrame = Xrm.Page.ui.controls.get("IFRAME_test");
var Url = IFrame.getSrc();
// Capture the parameters
var params = Url.substr(Url.indexOf("?"));
//Append the parameters to the new page URL
newTarget = newTarget + params;
// Use the setSrc method so that the IFRAME uses the
// new page with the existing parameters

C# code to Check Whether the User is Part of a Team in MS CRM 2011 using QueryExpression

C# code to Check Whether the User is Part of a Team in MS CRM 2011 using QueryExpression


QueryExpression teamQuery = new QueryExpression(“team”);
ColumnSet teamColumnSet = new ColumnSet(“name”);

teamQuery.ColumnSet = teamColumnSet;
teamQuery.Criteria = new FilterExpression();
teamQuery.Criteria.FilterOperator = LogicalOperator.And;
teamQuery.Criteria.AddCondition(“name”, ConditionOperator.Equal, “<Team Name>”);
teamQuery.AddLink(“teammembership”, “teamid”, “teamid”).AddLink(“systemuser”, “systemuserid”, “systemuserid”).LinkCriteria.AddCondition(“systemuserid”, ConditionOperator.Equal, context.UserId);



Share a Record to The Specific Team In MS CRM 2011 using C# Code

Share a Record to The Specific Team In MS CRM 2011 using C# Code to share a incident record to a team

//Paste the Below code in your plugin or any custompage

private void ShareRecordToBuTeam(IOrganizationService service, string SharedRecordEntitySchemaName, Guid SharedRecordGuid , string TeamLogicalName,Guid TeamGuid)
GrantAccessRequest grantShareingRequest = new GrantAccessRequest()
Target = new EntityReference(SharedRecordEntitySchemaName,SharedRecordGuid),
PrincipalAccess = new PrincipalAccess()
Principal = new EntityReference(TeamLogicalName,TeamGuid),
AccessMask = AccessRights.ReadAccess
GrantAccessResponse AccessResponse = (GrantAccessResponse)service.Execute(grantShareingRequest);

//Pass the parameter to the Function as below


ShareRecordToBuTeam(service,”<entity Logical Name>”,<SharedRecordGUID>, “<team logical name>”,<TeamGuid>);



Retrieve Multiple Entity Records and Bind to The Asp.Net DataGridView Control Dynamically Using C#

Retrieve Multiple Entity Records and Bind to The Asp.Net DataGridView Control Dynamically Using C# code 

After getting the entity collection using the Query Objects please follow the below code.

EntityCollection RetrieveContactResultCollectionUsingEnqCallerId = GetEntityCollectionDateUsingQueryExpression(“contact”, RetrieveContactColumnSet, “telephone1”, EnquirerCallerIdNumber);

if (RetrieveContactResultCollectionUsingEnqCallerId.Entities.Count >= 1)
DataSet ds = new DataSet();
DataTable dt = new DataTable();

foreach (var ContactResultUsingCallerId in RetrieveContactResultCollectionUsingEnqCallerId.Entities)
DataRow dr = dt.NewRow();

dr[“Salutation”] = ContactResultUsingCallerId.GetAttributeValue<OptionSetValue>(“ica_salutation”).Value.ToString();
dr[“Lastname”] = ContactResultUsingCallerId.GetAttributeValue<string>(“lastname”);
dr[“Telphone1”] = ContactResultUsingCallerId.GetAttributeValue<OptionSetValue>(“Telphone1”).Value.ToString();
dr[“Telphone2”] = ContactResultUsingCallerId.GetAttributeValue<string>(“Telphone1”);
dr[“Emailaddress1”] = ContactResultUsingCallerId.GetAttributeValue<string>(“emailaddress1”);
dr[“Gender”] = ContactResultUsingCallerId.GetAttributeValue<string>(“gender”);
dr[“Address1_telephone1”] = ContactResultUsingCallerId.GetAttributeValue<string>(“address1_telephone1”);
dr[“Birthdate”] = ContactResultUsingCallerId.GetAttributeValue<DateTime>(“birthdate”).ToString();




// You are now ready to bind your DataSet to your GridView
ContactSearchDataGrid.DataSource = ds;


Retrieve Optionset label in ASP.Net using CRM Service

Retrieve Optionset label in Asp.Net Using C# code



public static string GetOptionSetValueLabel(IOrganizationService service, string entity, string attribute, OptionSetValue option)
string optionLabel = String.Empty;

RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
EntityLogicalName = entity,
LogicalName = attribute,
RetrieveAsIfPublished = true

RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)service.Execute(attributeRequest);
AttributeMetadata attrMetadata = (AttributeMetadata)attributeResponse.AttributeMetadata;
PicklistAttributeMetadata picklistMetadata = (PicklistAttributeMetadata)attrMetadata;

// For every status code value within all of our status codes values
// (all of the values in the drop down list)
foreach (OptionMetadata optionMeta in
// Check to see if our current value matches
if (optionMeta.Value == option.Value)
// If our numeric value matches, set the string to our status code
// label
optionLabel = optionMeta.Label.UserLocalizedLabel.Label;

return optionLabel;


Fill Asp.Net DropDown Values with MS CRM Optionset Meta Data

Retrieve Optionset MetaData using CRM Service and Fill Asp.Net Drop Down Dynamically Using C#


public Dictionary<int, string> RetrieveOptionsetMetadata(IOrganizationService service)
//Dictionary to store value and text

Dictionary<int,string> AspDropdownDatasource= new Dictionary<int,string>();

//Create request to fetch optionset

RetrieveAttributeRequest RetAttRequest = new RetrieveAttributeRequest
EntityLogicalName =”EntityName”,
LogicalName =”OptionsetFieldName”,
RetrieveAsIfPublished =true

// Execute the request

RetrieveAttributeResponse RetAttResponse = (RetrieveAttributeResponse)service.Execute(RetAttRequest);

PicklistAttributeMetadata _PicklistAttributeMetadata = (PicklistAttributeMetadata)RetAttResponse.AttributeMetadata;
OptionMetadata[] optionList =_PicklistAttributeMetadata.OptionSet.Options.ToArray();

foreach (OptionMetadata _Optionset in optionList)
AspDropdownDatasource.Add(int.Parse(_Optionset.Value.ToString()), _Optionset.Label.UserLocalizedLabel.Label);
return AspDropdownDatasource;