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

            }
            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

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: http://mscrmblog.net/downloads/JSWebCall.zip
  • 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:
window.setTimeout(RetrieveXML,1000);
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("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

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

  • 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

Welcome to MSCRMBlog.net

Posted by on Aug 12, 2008 in CRM 4.0, Customizations, Deployment, General, JavaScript, Licensing, Plug-ins, SDK |

Hi Guys,

Welcome to my new Blog. My name is Ibrahim Sukari (refer to the About Me page for more info), i am a CRM developer. The company i work for is called RightServ. We have done quiet a few CRM deployments with hefty customizations. I basically created this blog to give back to the community that indeed helped me during those tough deployments. I’ll be posting a range of stuff including code and how-to’s. I want this blog to be on top and become a ALL-IN-ONE resource for Microsoft Dynamics CRM!

Thanks!

Read More
%d bloggers like this: