Quick Create Phone Call Activity in Dynamics CRM 4.0

Paul Nieuwelaar, 25 August 2010

The other day I was led to a very handy website, where I found a piece of JavaScript that made creating a phone call activity from a contact very easy. The website where I found the code gave a block of JavaScript that could be added to the Contact forms onLoad event, and would work unchanged. How it works is that when you double click into the mobile phone field of the contact, a phone call activity opens with the contact already being set in the recipient and regarding fields, similar to if you created an activity from the left hand side of the contact.

The code supplied by yousavirtual.com looks something like this:

crmForm.all.mobilephone.ondblclick = function () {

    var ObjectTypeCode = 4210;

    var RequisitionTypeCode = crmForm.ObjectTypeCode;

    var UrlInfo = GetWindowInformation(4210);

    var WindowFeatures = 'toolbars=0,width=' + UrlInfo.Width + ',Height=' + UrlInfo.Height + ',Left=10,top=90';

    var Parameter = (ObjectTypeCode > 9999) ? '?etc=' + ObjectTypeCode : '?pId=' + crmForm.ObjectId + '&pType=2&pName=' + crmForm.all.firstname.DataValue + '%20' + crmForm.all.lastname.DataValue + '&partyid=' + crmForm.ObjectId + '&partytype=2&partyname=' + crmForm.all.firstname.DataValue + '%20' + crmForm.all.lastname.DataValue + '&partyaddressused=&contactInfo=';

    var WindowUrl = '/' + ORG_UNIQUE_NAME + '/' + UrlInfo.Url + Parameter;

    var WindowName = 'Appel';

 

    window.open(WindowUrl, WindowName, WindowFeatures);

}

Before I tried this on our live server, I first tested it on a VPC, and it seemed to work fine. When you double-click into the mobile phone field, you get a phone call activity pop up like below.

However when I implemented it on our live server, it didn’t work for some reason. After realising the URL that the JavaScript was building was different to the URL that was used by Dynamics CRM phone call activities, I had to make a few adjustments to the code.

Another thing I noticed is that the ‘Phone Number’ field on the phone call activity was not pulling from the contact, and I wanted whatever phone number I double clicked on to be pulled through to the phone call activity.

Most of the code below is the same as above, but I’ve made a few minor adjustments, mainly so it would work on our CRM. You may find either code works for you. This is the code that I ended up using:

if (crmForm.FormType == 2) {

    crmForm.all.mobilephone.ondblclick = function () {

        var ObjectTypeCode = 4210;

        var RequisitionTypeCode = crmForm.ObjectTypeCode;

        var UrlInfo = GetWindowInformation(4210);

        var WindowFeatures = 'toolbars=0,width=' + UrlInfo.Width + ',Height=' + UrlInfo.Height + ',Left=10,top=90';

        var Parameter = (ObjectTypeCode > 9999) ? '?etc=' + ObjectTypeCode : '?pId=' + crmForm.ObjectId + '&pType=2&pName=' + crmForm.all.firstname.DataValue + '%20' + crmForm.all.lastname.DataValue + '&partyid=' + crmForm.ObjectId + '&partytype=2&partyname=' + crmForm.all.firstname.DataValue + '%20' + crmForm.all.lastname.DataValue + '&partyaddressused=&contactInfo=' + crmForm.all.mobilephone.DataValue;

        var WindowUrl = '/' + UrlInfo.Url + Parameter;

        var WindowName = 'Appel';

 

        window.open(WindowUrl, WindowName, WindowFeatures);

    }

}

As you can see the highlighted parts of the code are the things I have added in.

The first part highlighted is basically telling the code to only run if the form is an update form, because you shouldn’t need to/be able to create phone call activities if the form is a create or read only form.

The next highlighted line is adding in the phone number, so that it will be pulled through to the phone call activity. As you can see, the attribute name (mobilephone) is the same here as it is at the top of the code, so that only the phone number you double click on will be pulled through.

The final part I highlighted is what was causing the URL to not work on our live server. Just removing “'/' + ORG_UNIQUE_NAME +” seemed to make it work for me.

The final things to note are the bolded parts. Where it has “mobilephone” is the name of a phone field on the contact that you want to be able to double click on, change both instances of this to get the phone number pulling through to the activity. And where it has “4210” is the object type code of the phone call activity, which should be the same by default, but if not you can change it.

Once you get this working on the mobile phone, you can copy and paste the entire code into the contact forms onLoad again, and change both instances of “mobilephone” to the name of another phone field on the form, such as “telephone1” (Business Phone). This way users can click on either Mobile Phone or Business Phone to create a phone call activity with that number.

I hope this works as well for you as it did for me, and thanks again to yousavirtual.com for providing the code.