Thursday, December 30, 2010

Add Tooltip to form fields

To add a tooltip at some field on form, add following snippet in the form On Load event.

var element = document.getElementById("firstname_c");
element.title = "This is the First Name field.";

Happy Coding...

Labels: , , , ,

Finding the pipeline in which plugin is executing

The InvocationSource property is an integer value that you can use to determine whether the current plug-in is running in a child pipeline or Parent pipeline.

MessageInvocationSource Values

Field : Child
Value : 1
Description : Specifies a child pipeline

Field : Parent
Value : 0
Description : Specifies a parent pipeline

Happy Coding...

Labels: , , , , , , , ,

Wednesday, December 29, 2010

Get selected item(s) in CRM grid

The following will retrieve an array containing the Id values of the selected records in the grid:
// get array of selected records
var a = document.all['crmGrid'].InnerGrid.SelectedRecords;
var selectedItems = new Array(a.length);
for (var i=0; i < a.length; i++)
{
selectedItems[i] = a[i][0];
}
alert(selectedItems);

//To get all of the records in the grid (ie. “All Records on Current Page”):
// array of all records on current page
var iTotal = document.all['crmGrid'].InnerGrid.NumberOfRecords;
var o = document.all['crmGrid'].InnerGrid;
var allItems = new Array;
var ii = 0;
for (var i=0; i < iTotal; i++)
{
allItems[ii] = o.rows[i].oid;
ii++;
}
alert(allItems);

Happy coding...

Labels: , , , , , , ,

CrmDateTime conversion to DateTime

1.Convert.ToDateTime(crmdatetime.Value)
2.DateTime.Parse(crmdatetime.Value)

For more information on the CrmDateTime, look in the SDK:

Check here

Labels: , , , , , , ,

Tuesday, December 28, 2010

Dynamic generation of Word(.DOCX) file

Just came across a problem few days back when creating dynamic word(.docx) file. After creation, the com object was still sitting there in the process list, which gave me some weird messages everytime and it always creates the new instance of the word object. I tried a lot and atlast found this solution in MSDN. We need to release the com object finally after completion of our work. Use the below function in your code and call this after you have completed the dynamic generation process.


private void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch { }
finally
{
o = null;
}
}


Microsoft.Office.Interop.Word.ApplicationClass oWord = new Microsoft.Office.Interop.Word.ApplicationClass();

*****
Your logic for dynamic generation of word file(in my case)
*****

NAR(oWord);

You are done. Now it should work as expected.

Happy coding..

Labels: , , , , , , , , ,

Hiding CRM Elements

var HIDE = 'none';
var SHOW = 'block';

// Function to show/hide CRM controls on a CRM form
// such as text boxes, lookups, pick-lists etc.
function SetCrmControlVisible(elementName, visibility)
{
SetElementVisible(elementName + '_c', visibility);
SetElementVisible(elementName + '_d', visibility);
}

// Fuction to show/hide specific elements on a CRM form
// such as the left-hand link items (More Addresses, Workflows
// and even custom ISV links
function SetElementVisible(elementId, visibility)
{
var elem = document.getElementById(elementId);
if (elem != null)
{
elem.style.display = visibility;
}
}

// Function to show/hide Navigation "Sections" in the left-hand
// links (Such as Sales, Marketing and Service)
function SetParentElementVisible(elementId, visibility)
{
var elem = document.getElementById(elementId);
if (elem != null && elem.parentElement != null)
{
elem.parentElement.style.display = visibility;
}
}


Add the above code to the Entity OnLoad (and ensure that you enable the event) and after that you are ready to show/hide elements on the CRM form.

By using the IE Developer toolbar, you can retrieve the id of the element to be hidden (note in IE 8 this come built in and is not a seperate download). Open an entity record (in this case a Contact), press CTRL+N to open it in a new window, and then select IE Developer Toolbar.

Using the controls, select the item you want to hide and get the element id. In this case I have selected the “Opportunities” link and the id is “navOpps”



Using this, I can call the SetElementVisible function like this to hide the Opportunities link:


SetElementVisible('navOpps', HIDE);


To hide the entire “Sales” section from the left-hand navigation pane, I can once again find the id, but this time is of the parent item which would result in the following call to hide it:


SetParentElementVisible('_NA_SFA', HIDE);


Lastly, to hide an element on the form such as the “Job Title” field, you once again should use the IE Developer Toolbar to retrieve the element id and then call the SetCrmControlVisible function:


SetCrmControlVisible('jobtitle', HIDE);


By selecting either the textbox or the label, for the Job Title, the returned id will be “jobtitle_c” or “jobtitle_d” – remove everything including and after the “_” and pass that to the SerCrmControlVisible function and you are done!

Happy coding!

Labels: , , , , , , ,

Sunday, June 6, 2010

CRM 5.0 Features

The new CRM 5.0 features video is out.

Watch the video in the below link :

CRM 5.0 Features Video

Labels: , , , ,