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.

Before:

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

After:

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

            }
            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

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: