Home > CRM 4.0, Customizations, Plug-ins > Company name on the phone call form.

Company name on the phone call form.

September 18th, 2008

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; }

            }
            else
            { return; }

            try
            {

                //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));
                                }

                                break;
                            }
                        }                      
                      
                    }
                    else
                    {
                      
                       return;
                    }
                }
                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

MSCRM-Admin CRM 4.0, Customizations, Plug-ins , , , , ,

  1. January 4th, 2009 at 14:20 | #1

    Thanks for your help!

  2. May 13th, 2009 at 13:35 | #2

    I just love your weblog! Very nice post! Still you can do many things to improve it.

  3. September 25th, 2009 at 11:32 | #3

    ???????? ??? ????????? ??????? ??? ?????? ?????????. http://1id.ru

  4. September 25th, 2009 at 21:33 | #4

    XXX-Vip Video - ???????? ????? ?????? ??? ??? ?????? ??? mscrmblog.net

  5. September 26th, 2009 at 15:49 | #5

    ?? ??… ?? ???? ???????? ???????? ??? http://kinozalvip.ru

  6. October 24th, 2009 at 01:17 | #6
  7. October 26th, 2009 at 10:25 | #7

    ????? ???????? ???,????? ???? - filmkolor.ru

  8. October 29th, 2009 at 00:48 | #8

    ?????? 5 ???? ???? ??????????? ???????? ?????? ?????????? ????

  9. lr
    November 25th, 2009 at 18:12 | #9

    Is there any way to do this WITHOUT adding a plug-in? Because plug-ins aren’t supported in CRM Online. Could you do this via webservice only?

  10. December 6th, 2009 at 17:21 | #10

    ? ??? ??? ?????? ??????, ??? ??? ? ????

  1. October 17th, 2009 at 06:24 | #1
  2. January 15th, 2010 at 11:48 | #2
  3. January 20th, 2010 at 04:14 | #3
  4. January 26th, 2010 at 20:06 | #4
  5. February 7th, 2010 at 16:16 | #5
  6. February 23rd, 2010 at 22:34 | #6
  7. February 24th, 2010 at 20:19 | #7
  8. February 25th, 2010 at 23:26 | #8
  9. February 27th, 2010 at 00:56 | #9
  10. February 27th, 2010 at 23:03 | #10
  11. March 1st, 2010 at 09:47 | #11
  12. March 2nd, 2010 at 22:53 | #12
  13. March 3rd, 2010 at 05:34 | #13
  14. March 5th, 2010 at 09:17 | #14
  15. March 7th, 2010 at 17:40 | #15
  16. March 12th, 2010 at 13:18 | #16
  17. March 14th, 2010 at 14:40 | #17
  18. March 15th, 2010 at 13:25 | #18
  19. March 16th, 2010 at 19:19 | #19
  20. March 17th, 2010 at 19:26 | #20
  21. March 18th, 2010 at 22:27 | #21
  22. March 19th, 2010 at 22:55 | #22
  23. March 22nd, 2010 at 00:56 | #23
  24. March 23rd, 2010 at 16:25 | #24
  25. March 24th, 2010 at 22:43 | #25
  26. March 25th, 2010 at 19:16 | #26
  27. March 26th, 2010 at 16:45 | #27
  28. April 2nd, 2010 at 08:08 | #28
  29. April 17th, 2010 at 10:43 | #29
  30. April 29th, 2010 at 16:05 | #30
  31. June 6th, 2010 at 08:16 | #31
  32. June 12th, 2010 at 05:28 | #32
  33. June 26th, 2010 at 18:27 | #33
  34. June 30th, 2010 at 00:50 | #34
  35. July 9th, 2010 at 04:55 | #35
  36. July 12th, 2010 at 23:44 | #36
  37. July 13th, 2010 at 23:12 | #37
  38. July 20th, 2010 at 01:24 | #38
  39. August 17th, 2010 at 20:22 | #39
  40. August 18th, 2010 at 04:47 | #40
  41. August 18th, 2010 at 14:38 | #41
  42. August 19th, 2010 at 12:16 | #42