Search This Blog

Friday, February 24, 2012

Contact Info / Label (CRM 2011)

Although the built-in Word Mail Merge can create nice personalized mailing labels, sometimes users don't want to go through all the steps Word requires to generate just one label. That is why we add a "Contact Info Summary" concatenation on most of our clients' Account and Contact forms, for a quick copy-paste option.

The code below applies to Contacts, but it can be easily adapted for the Account, Lead and Address forms.

1.    Start by creating a new memo attribute (“Multiple lines of text”) that will hold your concatenated label. In our example, we named it “new_contactinfosummary”. We recommend making it non-searchable to keep the fields list cleaner.

2.    Add the field to the form. Layout is up to you, obviously, but we recommend making it read-only, to ensure that users don’t start typing in there, thinking individual fields will update from there (true story…).


3.    Add the following 2 functions in a web resource.

function BuildContactInfoSummary() {
    //------- Load the function to build the Contact Info Summary
    var Label = "";

    if (Xrm.Page.getAttribute("salutation").getValue() != null)
    { Label = Xrm.Page.getAttribute("salutation").getValue() + " "; }

    if (Xrm.Page.getAttribute("firstname").getValue() != null)
    { Label = Label + Xrm.Page.getAttribute("firstname").getValue() + " "; }

    if (Xrm.Page.getAttribute("lastname").getValue() != null)
    { Label = Label + Xrm.Page.getAttribute("lastname").getValue(); }

    if (Xrm.Page.getAttribute("jobtitle").getValue() != null)
    { Label = Label + ", " + Xrm.Page.getAttribute("jobtitle").getValue(); }

    var OrgName = Xrm.Page.getAttribute("parentcustomerid").getValue();
    if (OrgName != null)
    { Label = Label + "\r\n" + OrgName[0].name; }

    if (Xrm.Page.getAttribute("address1_line1").getValue() != null)
    { Label = Label + "\r\n" + Xrm.Page.getAttribute("address1_line1").getValue(); }

    if (Xrm.Page.getAttribute("address1_line2").getValue() != null)
    { Label = Label + "\r\n" + Xrm.Page.getAttribute("address1_line2").getValue(); }

    //ENABLE THE FOLLOWING IF YOUR FORM INCLUDES STREET 3:
    //        if (Xrm.Page.getAttribute("address1_line3").getValue() != null)
    //        { Label = Label + "\r\n" + Xrm.Page.getAttribute("address1_line3").getValue(); }

    if (Xrm.Page.getAttribute("address1_city").getValue() != null)
    { Label = Label + "\r\n" + Xrm.Page.getAttribute("address1_city").getValue(); }

    if (Xrm.Page.getAttribute("address1_stateorprovince").getValue() != null)
    { Label = Label + ", " + Xrm.Page.getAttribute("address1_stateorprovince").getValue(); }

    if (Xrm.Page.getAttribute("address1_postalcode").getValue() != null)
    { Label = Label + "   " + Xrm.Page.getAttribute("address1_postalcode").getValue(); }

    if (Xrm.Page.getAttribute("address1_country").getValue() != null)
    { Label = Label + "    " + Xrm.Page.getAttribute("address1_country").getValue(); }

    if (Xrm.Page.getAttribute("telephone1").getValue() != null)
    { Label = Label + "\r\nBusiness Phone: " + Xrm.Page.getAttribute("telephone1").getValue(); }

    if (Xrm.Page.getAttribute("emailaddress1").getValue() != null)
    { Label = Label + "\r\n" + Xrm.Page.getAttribute("emailaddress1").getValue(); }

    Xrm.Page.getAttribute("new_contactinfosummary").setValue(Label);
    Xrm.Page.getAttribute("new_contactinfosummary").setSubmitMode("always");
}

function UpdateContactInfoSummary() {
    //------Update the Contact Info Summary on updatable records
    if (Xrm.Page.ui.getFormType() == 2) {

        //------Force a save if the Contact Info Summary was empty ** NOTE: remove this following statement if you DO NOT want to force a save -- i.e., if you have onSave code that you do not want triggered right away
        if (Xrm.Page.getAttribute("new_contactinfosummary").getValue() == null) {
            BuildContactInfoSummary();
            Xrm.Page.data.entity.save();
        }
        else {
            BuildContactInfoSummary();

            //------Disable the "do you want to save?" alert if the Contact Info Summary hasn't changed
            if (crmForm.all.new_contactinfosummary.IsDirty) crmForm.detachCloseAlert();
        }
    }
}

4.    Add UpdateContactInfoSummary as an onLoad event and BuildContactInfoSummary as an onSave event.

5.    Save and publish customizations.

Wednesday, February 22, 2012

Report Uploading Error

I was getting an error uploading custom reports on a customer's CRM 4.0 deployment.  When I would upload the report, I would get the following error:


Checking Google and CRM Forums it seems like there are a lot of people with this error.  A common mistake is creating a report in a new version of Visual Studio (2008) and targeting an older version of SQL (2005) reporting services.  This was not my problem, and I had been able to upload reports before.

Now, not exactly sure why, but I have had issues with reports on CRM before, and the process of playing around with encryption keys has resolved some issues.

On the SQL Report Server, I went to Start -> All Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> Reporting Services Configuration Manager



I clicked connect and then clicked on encryption keys, and then backup. 

I entered a filename and path, passwords and that was it! 



I exited Reporting Services Configuration Manager and I could now upload custom CRM reports with ease.

I hope this helps someone in the future.  If anyone could give an explanation why this would fix it, I would appreciate it!

Cheers
Nick