Filtered Lookup in CRM 2011


To get the filtered lookup functionality in CRM 2011 we can make use of the

addCustomView Method of Xrm.Page.ui control.


Something similar to this

Here we have a custom entity name Case which has 1-n relationship with Contact Entity.

Now we want to show only those contact records in lookup which are associated with a particular case record.

We can add the code to the onload of the Entity.

// View ID --> Generate and Assign a new guid.

var viewId = "{C0F1DD64-1BF3-450D-BCDE-DF4732DE1606}";

// Set the entity name
 var entityName = "contact";
 // Give a meaningful name to the custom view
 var viewDisplayName = "Case Member View";

// Create the Advanced find query and download the fetch xml
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='contact'>" +
"<attribute name='fullname' />" +
" <attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='new_caseid' operator='eq' uiname='new case' uitype='new_case' value="+caseID+"/>" +
"</filter>" +
"</entity>" +
"</fetch>";

// specify the layout for the results and which field to display
var layoutXml = "<grid name='resultset' " +
"object='1' " +
"jump='name' " +
"select='1' " +
"icon='1' " +
"preview='1'>" +
"<row name='result' " +
"id='contactid'>" +
"<cell name='fullname' " +
"width='100' />" +
"</row>" +
"</grid>";
// specify the schemaname of the lookup control
var lookupControl = Xrm.Page.ui.controls.get('new_clientid');
// set the parameters

lookupControl.addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

Accessing IFrame through JavaScript


Accessing IFrame through JavaScript

window.frames[0].location

window.frames[“myframename”].location // through name

document.getElementById(‘myframeid’).src // through id

Accessing a div element name myDiv within Iframe

window.frames[“myframename”].document.getElementById(‘myDiv’).innerHTML

document.getElementById(‘myframeid’).contentDocument.getElementById(‘myDiv’).innerHTML

Accessing a div element name myDivInside within Iframe(myfframeid) which itself is inside an Iframe(myframeid)

document.getElementById(‘myframeid’).contentDocument.getElementById(‘myfframeid’).contentWindow.document.getElementById(‘myDivInside’).innerHTML

http://www.dyn-web.com/tutorials/iframes/

Bye.

CS1026: ) expected error when using IFrame in Content Page


Hi I had the following iframe defined in one of my aspx page.

<iframe id=”MyIframe” src=”http://www.bing.com&#8221; runat=”server” onload=”CallHello();”></iframe> 

The page was working fine. However as soon as I specified the same iframe inside a master page, I started getting following error. 

Compiler Error Message: CS1026: ) expected 
Source Error: 

 
 Line 4: </asp:Content>
Line 5: <asp:Content ID=”Content2″ ContentPlaceHolderID=”ContentPlaceHolder1″ Runat=”Server”>

Line 6: <iframe ….src=http://www.bing.com….

Line 7: </asp:Content>

Line 8:

 

So here to resolve the error either remove the runat or onload attribute.

 

Bye. 

Get value for OptionSet in CRM 2011


To get the value for OptionSet we can use the following function

private
string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)
{

RetrieveAttributeRequest retrieveAttributeRequest = new
RetrieveAttributeRequest
{

EntityLogicalName = entityName,

LogicalName = attributeName,

RetrieveAsIfPublished = true

};
// Execute the request.

RetrieveAttributeResponse retrieveAttributeResponse =(RetrieveAttributeResponse)
service.Execute(retrieveAttributeRequest);
// Access the retrieved attribute.

Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata =(Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)

retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
string selectedOptionLabel = string.Empty;

foreach (OptionMetadata oMD in optionList)
{
if (oMD.Value == selectedValue)
{selectedOptionLabel = oMD.Label.UserLocalizedLabel.Label;

}

}
return selectedOptionLabel;

}

http://www.codeproject.com/Tips/553178/Get-the-OptionsetValue-and-OptionsetText-for-Dynam

 

Hope it helps !

HyperLinkField and RowDataBound in ASP.NET


To access the HyperLinkField control with the RowDataBound event of the GridView, we can use the following code (refer the column cell)

protected void gridCaseMember_RowDataBound(object sender, GridViewRowEventArgs e){
if (e.Row.RowType == DataControlRowType.DataRow){
HyperLink myLink = (HyperLink)e.Row.Cells[0].Controls[0];

myLink.NavigateUrl = http://www.bing.com&#8221;;    }

}

http://forums.asp.net/t/1142271.aspx 

Hope it helps !

Hiding Columns in GridView when AutoGenerateColumns is True


Hi,

If we have set AutoGenerateColumns property of the GridView as true and binding it to a data source, we will not be able to remove columns from it using the Remove or RemoveAt functions of Columns.

myGridView.Columns.Remove or RemoveAt

So to remove the columns we can make use of RowDataBound event.

protected void myGridView _RowDataBound(object sender, GridViewRowEventArgs e){
// hide the second and third column
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Visible=false;

e.Row.Cells[2].Visible=false;}
else
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[1].Visible = false;

e.Row.Cells[2].Visible = false;}

}
Hope it helps!!

Nishant Rana's Weblog

Everything related to Microsoft .NET Technology

Skip to content ↓