Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Tuesday, October 4, 2011

Changing the Font Color of a Read-Only Field in MS CRM 2011

I recently got a request to change the font color of certain fields in CRM 2011. I used the below code to achieve this:

function setColor() {
    if (document.getElementById("new_name") != null) {
        //Add the below line if the field is disabled
        document.getElementById("new_name").disabled = false;
        //The below line changes the font color
        document.getElementById("new_name").style.color = "red";
    }
}
Note: Accessing the DOM as shown above is totally unsupported. I had to use the above method since I was not able to find any supported way of achieving this functionality

Thursday, September 1, 2011

Enabling JScript/JavaScript in Bulk Edit CRM 2011

I recently came across a situation where I had to use Jscript while Bulk Editing the records in CRM 2011. As we all know, this is not possible out of the box but thanks to Michael Höhne (http://www.stunnware.com/crm2/topic.aspx?id=BulkEdit) and Microsoft for providing with the KB article (http://support.microsoft.com/kb/949941)

Here is what we need to do:

1. Export the entity as a solution for which JScript needs to be enabled during Bulk Edit.
2. Open the customization.xml
3. Add BehaviorInBulkEditForm="Enabled" to the event handlers as shown below
 
<
event name="onchange" application="false" active="false" attribute="new_day" BehaviorInBulkEditForm="Enabled"
>

<
event name="onsave" application="false" active="false" BehaviorInBulkEditForm="Enabled"
>

4. Save and Import the solution. Your JScript code should now be triggered!

 --Srihari

Friday, March 4, 2011

Simple Filtered Lookup based on Picklist Values


I had a parent entity containing records classified into 2 different disease categories ('Diabetes' and 'Cholestrol').
In my related entity, there was a picklist which had the above 2 disease categories. The criteria was that when the user selected a particular disease cateogry in the picklist, the parent entity lookup should show as a pop-up showing only the corresponding disease category records.
Ex: If the user selects ‘Diabetes’ in the picklist, then the lookup should pop-up showing only records of type ‘Diabetes’. After some searching, I found this blog:http://advantageworks.blogspot.com/2008/02/pseudo-filtered-lookup-dialog-in.html, which was describing a similar scenario. Here is how I implemented this:
1. I went into customizations and opened my parent entity.
2. Then I clicked on “Forms and views” and opened the lookup view.
3. Then I clicked on “Add Find Columns” and selected “Disease Category” column.
4. Saved and Published the entity
5. Next, I opened my related entity’s form.
6. In the onchange event of my picklist, I wrote the following code:

if(crmForm.all.new_Picklist.SelectedText=="Diabetes")
{
var criteria= 'Diabetes';
crmForm.all.new_parentLookupId.additionalparams =  'search=' + criteria;
crmForm.all.new_parentLookupId.click(); // Launch the parent lookup as a popup.
} 
7. Save and publish the related entity. So, basically this is the same as opening the lookup and typing ‘Diabetes’ in the search box of the lookup. It’s not filtered in a strict sense.
–Srihari.

Accessing ASP.NET controls within an IFRAME in CRM 4.0


There was a requirement to disable an drop-down list which was in an IFRAME in a CRM form.
The below code allowed me to access the value of the ASP.NET drop-down list:
document.frames.IFRAME_Test.document.all.DropDownList1.value;
and the below code allowed me to disable it:
document.frames.IFRAME_Test.document.all.DropDownList1.disabled= true;