Show no. of open or closed activities (history) on the CRM form.

Posted by on May 18, 2009 in CRM 4.0, Customizations, JavaScript |

Hello all,

Have you ever wanted to see the total no. of outstanding/completed activities on a Case, Account, Opportunity, Contact etc..?  

Well now you can, simply add the following JavaScript code to the onLoad event of the entity, it will query the webservice and it will give you the exact count of open/closed activities.

Update: 9th March 2010 – I have updated the code below and tested.

Any comments or suggestions are welcome!

Read More

Add custom toolbar buttons to the Case Entity form.

Posted by on May 17, 2009 in CRM 4.0, Customizations, JavaScript |

Hi All,

Have you ever wanted to add some toolbar buttons to the CASE/CONTACT/ACCOUNT form?

Well now you can, you can use the ISV.config provided by CRM.

  1. Export the ISV Config Customizations from CRM
  2. Edit the XML file
  3. Find the <entity name=”incident”> node and add the following – I couldn’t paste the XML because of wordpress limitations.

  4. Note: the following are custom images: taskicon.gif, emailicon.gif and phonecallicon.gif.

  5.  Save the XML and import into CRM and publish the customizations.

Code explantion:

JavaScript="locAddActTo(4210)" PassParams="0" WinParams="" WinMode="0" Client="Web, Outlook" AvailableOffline="true"

Here we are using the CRM javascript function locAddActTo() and using the entity identifier (this being a phone call) which is located in the SDK and we are telling CRM to show this button is Outlook and the web version of CRM

JavaScript="resolve();" PassParams="0" WinParams="" WinMode="0" Client="Web, Outlook" AvailableOffline="true"

We are using the resolve() function on the case entity form which will resolve the case like you would when going to the actions menu > resolve case

Read More

Hiding Sidebar Navigation (Related Entities)

Posted by on Sep 18, 2008 in CRM 4.0, Customizations, JavaScript |

Hi Guys,

Recently for a client, we had to create some many-to-1 relationship from Contact to Accounts & Opportunities.  We then had the problem of the related entity navigation on the side showing up.  They didn’t want to see all these related navigations. I added some onLoad code on the contact form to hide the Sidebar navigation.


The key is to get the relationship Elementid from the source code of the page (Press Ctrl + N to open new window, then click on the ‘view’ menu and click ’source’). Then find the Name of the Navigation and find the element id:

onLoad code:

document.getElementById("nav_new_contact_account_dm1").style.display = "none";
document.getElementById("nav_new_contact_account_dm2").style.display = "none";
document.getElementById("nav_new_contact_account_dm3").style.display = "none";
document.getElementById("nav_new_contact_account_dm4").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm1").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm2").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm3").style.display = "none";
document.getElementById("nav_new_contact_opportunity_dm4").style.display = "none";


I hope this helps you all and gives you some idea of how powerful JavaScript & CRM are.

-MSCRM Person

Read More

Company name on the phone call form.

Posted by on Sep 18, 2008 in CRM 4.0, Customizations, Plug-ins |

Hi there,

Have you struggled without the company name on the phone call form in CRM 4.0??

Usually when you create phonecall campaigns you notice that the regarding field of the campaign is the ‘Campaign Name’ and the Recipient is the ‘Lead full name’ which leaves us with no information what so ever telling us the company name.

This proccess involves creating a plug-in in Visual Studio 2005 or 2008 (what i use).

Step 1 – Creating custom attribute:

  • Create a custom attribute on the phone call form and call it ‘Company (Lead)’and stick this on the form. 
this is the custom attribute
this is the custom attribute

Step 2 – Creating Project:

  • Open up visual create and create a ‘Class Library Project’ and call it ‘GetCompanyPhoneCall’
  • Right click the project and click properties then click on the ‘Signing’ Tab on the left hand side.
  • Check the box: ‘Sign this assembly’, click on the drop down and select new and name it ‘SignedCRM’ and uncheck the ‘Protect the key file with a password’

Step 3 – Coding:

  • Insert the following code onto the page (you should delete everything that is currently on there minus what you just inputed. The code should look like the following.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
namespace Microsoft.Crm.Sdk.Walkthrough
 // this is the phone call update plugin.
    public class PhoneCallUpdateHandler : IPlugin
        public void Execute(IPluginExecutionContext context)
            // define a new Dynamic Entity as null

            DynamicEntity entity = null;

            // Check if the input parameters property bag contains a target
            // of the update operation and that target is of type DynamicEntity.

            if (context.InputParameters.Properties.Contains(“Target”) &&
               context.InputParameters.Properties[“Target”] is DynamicEntity)
                // Obtain the target business entity from the input parmameters.
                entity = (DynamicEntity)context.InputParameters.Properties[“Target”];

                // Verify that the entity represents a phonecall.
                if (entity.Name != EntityName.phonecall.ToString()) { return; }

            { return; }


                //we check if the category is empty then continue, else we stop.
                if (entity.Properties.Contains(“new_leadcompany”) == false)
                    if (entity.Properties.Contains(“to”) != false)

                        // Start the Service request
                        ICrmService service = context.CreateCrmService(true);

                        // this code works to simply display the GUID of the current record (phone call)!!!!!!! Guid boy = (Guid)context.OutputParameters.Properties[“id”];
                        // Note: the “to” field is a array of Dynamic entities — who knew!!
                        // First define a recipients for this Dynamic Entity array

                        DynamicEntity[] recipients = null;

                        // assign the “to” field on the form to the new array
                        recipients = (DynamicEntity[])entity.Properties[“to”];

                        //iterate through the recipients in the field and take the first lead that is available
                        foreach (DynamicEntity recipient in recipients)
                            Lookup recipientType = (Lookup)recipient.Properties[“partyid”];

                            // checking if the type is Lead
                            if (recipientType.type == “lead”)
                                // each array member is an ActivityParty — which then points to the Lead
                                // to get the Lead Guid, lookup on the “partyid” field
                                Guid recipientGuid = ((Lookup)recipient.Properties[“partyid”]).Value;

                                // now retrieve the Lead record, using the std entity name, the GUID you just got, and ask for all columns

                                lead retrieveLead = service.Retrieve(EntityName.lead.ToString(), recipientGuid, new Query.ColumnSet(new String[] { “leadid”, “companyname” })) as lead;

                                if (retrieveLead != null)
                                    //then input the company name into the category field
                                    entity.Properties.Add(new StringProperty(“new_leadcompany”, retrieveLead.companyname));

                else { return; }

            // this is the exception thrown if there is an error
            catch (System.Web.Services.Protocols.SoapException ex)
                throw new InvalidPluginExecutionException(“An error occurred in the AccountCreateHandler plug-in.”, ex);
The code above is self-explanatory, i have commented most of it for you guys to understand.

  • Next step is to register the plug-in using the plug-in registration tool.
  • Click on the ‘register’ menu and click ‘register new assembly’
  • Load the DLL file located in the project/bin folder
  • When done, click on the new assembly and right click and click ‘Register new step’

Message: update

Primary entity: phonecall

Pipeline Excution: pre-stage

  • Click register and exit. now create a new phone call with the ‘Lead’ as the recipient & Click Save. The turn out should be similar to below:

That concludes this post. If you need some help, don’t hesitate to comment on this post.

-MSCRM Person

Read More

JavaScript Web Service Call

Posted by on Aug 12, 2008 in CRM 4.0, Customizations, JavaScript, SDK |

Firstly i’d like to thank Michael Höhne for his great application that converts your c# code to Javascript. Basically you input your c# code and it sends a soap request and gets a reply and converts the request to Javascript so you can do it in realtime and not by a plug-in.

  • First grab the application from:
  • Open the project Visual Studio and double click on Form1.cs
  • Go to the “try” line and input your c# code to be converted.
  • Below i have my peice of code which just queries the systemuser entity for the GUID: F2EBE1D4-8E57-DD11-9225-000C29165D7E

  • Build the program and run the Application (from the bin\deubg dir)
  • Click on the start and wait until you see a response in the response tab.
  • Then move onto the Javascript tab and copy the code and paste it on a event (onchange, onload & onsave)
  • Heres my final code:
function RetrieveXML()
var xml = "" +
"" +
"" +
GenerateAuthenticationHeader() +
" " +
" " +
" " +
" systemuser" +
" " +
" " +
" businessunitid" +
" " +
" " +
" false" +
" " +
" And" +
" " +
" " +
" systemuserid" +
" Equal" +
" " +
" "+crmForm.all.ownerid.DataValue[0].id+"" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"" +
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

var resultXml = xmlHttpRequest.responseXML;
var businessUnitName = resultXml.getElementsByTagName("q1:businessunitid")[0].getAttribute('name');

  • Basically this gets the businessunit name from the ownerid in the field.

Hope this helps.

Read More

lookup field – onchange event

Posted by on Aug 12, 2008 in Customizations, JavaScript |

Hi Guys,

I have noticed that sometimes onchange code for a lookup needs some time (1sec) than to run its code.

Heres an example of a 1 second wait (wait until the lookup is populated with the lookup id, name etc):

window.setTimeout(getDetails, 1000);

function getDetails()
if(crmForm.all.ownerid.DataValue[0].id != null)
// do something

Read More
%d bloggers like this: