Thursday, December 30, 2010

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

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: , , , ,

Friday, November 20, 2009

Change the default entity in Lookup Window

For instance, in Opportunity form of Microsoft CRM if you want to change the “Potential Customer” field’s default entity from Account to Contact. You need to use the following piece of code in onLoad event of the Opportunity Form.

if ( crmForm.all.customerid != null )
{
    crmForm.all.customerid .setAttribute(”defaulttype”, “2″);
}

Remember to enable the event and then save and publish the opportunity entity.
 Following are codes of basic entities of Microsoft CRM 3 ;
  • Account    1
  • Contact     2
  • Lead         4
Thanks to Umar for pointing out this.

Happy Coding...

Labels: , , , , , ,

Multiple Column Sort in Dynamics CRM


Take a look at one of your views.
Select a Column so that the system is sorting on that column
Now move to another column and using the SHIFT, CNTL, MOUSE CLICK you can setup a secondary sort
Now move to another column and do it again..
Guess what: You now have three columns set to sort
So the question of the day then becomes. Which is the primary ?

Labels: , , , ,

Display a Google Map for an Account

Find the below code to add google map for an account in Dynamics CRM 4.0.

Make a new tab with an iFrame, add a custom bit value (yes or no radio buttons) called "shmap" and add this code as an onchange event.


if (crmForm.all.address1_postalcode.DataValue != null){
crmForm.all.IFRAME_gmap.src = "http://maps.google.com/maps?q=" +
crmForm.all.address1_line1.DataValue + "+" + crmForm.all.address1_city.DataValue + ",+" + crmForm.all.address1_postalcode.DataValue;
}
else
{
crmForm.all.IFRAME_gmap.src = "about:blank"
}

Thanks to Glen..

Happy Coding...

Labels: , , , , ,

Friday, October 23, 2009

Progress Bar in Dynamics CRM 4.0

To create a progress bar in Dynamics CRM 4.0 like the one below





You need the following


2.step.gif  
 

3.statusbar.gif - You can get this from the /_imgs/ folder in CRM

For step.gif, right click the .gif file and save it on your system.

crmprogressbar.js

function crmProgressBar(id) {
this.bar = $("#" + id);

this.bar.css({
'height': '23px',
'width': '357px',
'background': 'transparent url(img/statusbar.gif) no-repeat'
});

this.bar.find("div").css({
'height': '19px',
'width': '1px',
'background': 'transparent url(img/step.gif) repeat-x',
'position': 'relative',
'top': '2px',
'left': '3px'
});

this.step = function(percentage) {
var width = parseInt((percentage / 100) * 351);
if (width > 351) { width = 351; }

this.bar.find("div").css({ 'width': width + 'px' });
}
}

To implement follow the steps below.

1.Create a new html file
2.Create a new javascript file and copy the above code into it
3.Include a reference to the jQuery javascript library
4.Include a reference to the javascript in your html file
5.Add a "div" tag to the html file and give it an "id"
6.Add another "div" tag inside the "div" you created in step 4. and put a blank space
7.To initialize the progress bar; create a new variable to hold the progress bar, then create a new instance of the progress bar by specifying the "id" of the div you created in step 4.
eg: var progressBar1 = new crmProgressBar("id-of-div");
8.To step/increment the progress bar use the step() instance method
eg: progressBar1.step(10); // will increment to 10%;



<div id="p1">
<div>
 </div>
</div>

<script type="text/javascript">
var i = 5;
var cpb = null;

$(document).ready(function() {
cpb = new crmProgressBar("p1");
increment();
});

function increment() {
if (i <= 100) {
i += 5;
cpb.step(i);
setTimeout(increment, 1000);
}
}

</script>


Happy Coding..

You can find gperera's entry on Blog

Labels: , , , , ,

Tuesday, October 20, 2009

Backup, Restore & Publish Dynamics CRM Customizations Programmatically

Thanks to gperera in giving out this wonderful class.

Find the excerpts..

Here is a simple class you can use to backup, restore and publish dynamics crm customizations programmatically. Please keep in mind that dynamics crm customizations are additive, which means, if you import a set of customizations lets say a new attribute on the account entity and you restore a backup of the old customizations the new attribute on the account entity that was imported will not be deleted.

CrmCustomizations customizations = new CrmCustomizations(service);

You can backup to an xml file or a zip file by calling the Backup method. Backup method takes care of creating the xml or zip file by looking at the output file extension.

bool backedup = customizations.Backup(@".\customizations_backup.xml");

 or to a zip file

backedup = customizations.Backup(@".\customizations_backup.zip");

To restore a backup call the Restore method. You can pass it a .zip file //or a .xml file path.

bool restored = customizations.Restore(@".\customizations.xml");

Once you have restored you need to publish the customizations, to publish call the Publish method. It will publish all customizations.

bool published = customizations.Publish();

Find the class file below :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Crm.SdkTypeProxy;
using System.IO;
using System.IO.Compression;

public class CrmCustomizations
{
private CrmService _service = null;
public CrmCustomizations(CrmService service)
{
_service = service;
}

public bool Backup(string filePath)
{
bool backedup = false;

if (_service != null)
{
// grab all the customizations first
ExportAllXmlRequest request = new ExportAllXmlRequest();
ExportAllXmlResponse response = _service.Execute(request) as ExportAllXmlResponse;

byte[] data = Encoding.ASCII.GetBytes(response.ExportXml);

// prepare the backup file
if (File.Exists(filePath)) { File.Delete(filePath); }
FileStream fs = File.Create(filePath);

// check if we need to create a zip file
bool createZip = Path.GetExtension(filePath).ToLower().Equals(".zip");
if (createZip)
{
GZipStream gzs = new GZipStream(fs, CompressionMode.Compress, true);
gzs.Write(data, 0, data.Length);
gzs.Close();
}
else
{
fs.Write(data, 0, data.Length);
}
fs.Close();

backedup = true;
}

return backedup;
}

public bool Restore(string filePath)
{
bool restored = false;

if (_service != null && File.Exists(filePath))
{
string customizationXml = ReadData(filePath);
if (!string.IsNullOrEmpty(customizationXml))
{
ImportAllXmlRequest request = new ImportAllXmlRequest { CustomizationXml = customizationXml };
//_service.Execute(request);

restored = true;
}
}

return restored;
}

public bool Publish()
{
bool published = false;

if (_service != null)
{
PublishAllXmlRequest request = new PublishAllXmlRequest();
_service.Execute(request);

published = true;
}

return published;
}

private string ReadData(string filePath)
{
FileStream fs = File.Open(filePath, FileMode.Open);
byte[] data = new byte[fs.Length];

bool isZip = Path.GetExtension(filePath).ToLower().Equals(".zip");
if (isZip)
{
GZipStream gzs = new GZipStream(fs, CompressionMode.Decompress, true);
// decompress
MemoryStream stream = new MemoryStream();
byte[] b = new byte[4096];
while (true)
{
int n = gzs.Read(b, 0, b.Length);
if (n > 0) { stream.Write(b, 0, n); }
else { break; }
}

data = stream.ToArray();

stream.Close();
gzs.Close();
}
else
{
fs.Read(data, 0, data.Length);
}

fs.Close();

return Encoding.ASCII.GetString(data);
}
}

Happy coding...

Labels: , , , , , , , , , ,