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 = Xrm.Page.data.entity.getId();

 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 = Xrm.Page.data.entity.attributes.get("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";
        break;
    default:
        newTarget = "http://myServer/test/pageTwo.aspx";
        break;
}
//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
IFrame.setSrc(newTarget);
Cheers,

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);

 

Cheers,

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

For.eg. 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

Need

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

 

Cheers,

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();
dt.Columns.Add(“Salutation”);
dt.Columns.Add(“Lastname”);
dt.Columns.Add(“Telphone1”);
dt.Columns.Add(“Telphone2”);
dt.Columns.Add(“Emailaddress1”);
dt.Columns.Add(“Gender”);
dt.Columns.Add(“Address1_telephone1”);
dt.Columns.Add(“Birthdate”);

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();

dt.Rows.Add(dr);

}

ds.Tables.Add(dt);

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

Cheers,

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
picklistMetadata.OptionSet.Options)
{
// 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;
}

Cheers,

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;
}

 

Cheers,