Wednesday, June 29, 2011

CRM 2011 Postcode Lookup Solution Version 1.0

I have created this postcode lookup solution. You can download the managed solution from here. The name of the solution file is PostCodeSolution_1_0_managed. The solution consists of 4 files

  • new_Json2.js (Javascript webresource)
  • new_PostCodeScript(Javascript webresource)
  • new_postcode(custom entity to store postcode information)
  • new_SuburbOptions (HTML webresource)

How does it work:

  • User enters the postcode on postal code field and onchange event of the field, the solution will retrieve postcode records related to entered postcode.
  • If there is a record related to entered postcode, the solution will populate the state, suburb and country fields for you.
  • If there are more than one records related to entered postcode, solution will prompt you to select the appropriate entry.

In the following screen shot, I entered 2000 in postal code field and system prompt to pick the relevant city/suburb.

image

Pros:

  • Clean data entry: The solution will help to minimise data entry errors in address fields.
  • Don’t need to create custom picklist state/or country attributes.
  • Using built-in address fields means, don’t need to modified some of the built-in reports.

Cons:

  • The solution is working only address1_postalcode attribute of an entity. It can work on account , contact or any other entity that has built in address fields.
  • The solution is hard coded to fill built in adress1_city, address1_stateorprovince, address1_country fields only.

Version 2.0 :

I will release version 2.0 soon, which will not use hard coded attributes.

Installation Directions:

  1. Install the postcode solution.
  2. Open the account or contact entity form in customisation mode.
  3. Double click on Postal Code attribute.
  4. Add new_Json2.js and new_PostCodeScript to form libraries.
  5. Call loadPostCodeRequest function from new_PostCodeScript.Save the changes and publish them.

image





















6. Import the Postcodes.

image

  • Import the file into new_postcode entity.

    Note: You can download the US postal Codes from US ZIP CODES.

    You are good to go.

    Feedback please.

Thursday, June 16, 2011

Tips for using REST endpoints in CRM 2011(Rest endpoints browser)

Using REST endpoints with json2 are the simplest way to retrieve data in CRM 2011. The code is clean and simple. Here is a sample retrieve request

retrieveAccountsReq.open("GET", getRESTUrl() +

"/new_postcodeSet?$top=20&$select=new_name,new_Country,new_Suburb,new_State,new_postcodeId&$filter=new_name
eq ('"
+ postcode + "')", true);


The above request is used to retrieve the custom entity (new_postcode) dataset where new_name is equal to postcode.

The result will look like this
image
To get the fieldnames for an entity you can use http://servername:portnumber/organization name/XRMServices/2011/OrganizationData.svc/entitySet

The result will look like this

image

You can even paste the query in the browser and check the result of the query. The following query will display all the records with postcode 2010.

http://tcrm2010:5555/CRM/XRMServices/2011/OrganizationData.svc/new_postcodeSet?$select=new_name,new_Country,new_Suburb,new_State,new_postcodeId&$filter=new_name

The result will look like this

image

Conclusion

REST endpoints are the best way to retrieve data on client site. You can even see the result of the query in the browser.

Happy Programming……..

Wednesday, June 8, 2011

How to start a Dialog from Application Ribbon (CRM 2011)

To start the Dialog from the Application Ribbon, you need to 3 things
  1. Application Ribbon Button (and Button Images)
  2. JavaScript to call the Dialog
  3. Dialog
I have attached the unmanaged solution here. The solution contains the following components
image
  • “Application Ribbons” contains the definition of the button.
  • “new_custom16x16” and “new_custom32x32” are image files for the button.
  • “new_dialogjavascript” is a JavaScript web Resource. It contains the JavaScript code to open the dialog.
  • “Sales Call” is dialog script

Detail Explanation

Application Ribbon

   1:  <RibbonDiffXml>
   2:      <CustomActions>
   3:        <CustomAction Id="Sample.{!EntityLogicalName}.MainTab.MyURL.CustomAction" Sequence="41" Location="Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab.Workflow.Controls._children">
   4:          <CommandUIDefinition>
   5:            <Button Id="Sample.{!EntityLogicalName}.MainTab.MyURL.Button" Command="javascript.Command" LabelText="Sales Call" ToolTipTitle="Sales Call" ToolTipDescription="Sales Call" TemplateAlias="o1" Image16by16="$webresource:new_custom16x16" Image32by32="$webresource:new_custom32x32" />
   6:          </CommandUIDefinition>
   7:        </CustomAction>
   8:      </CustomActions>
   9:      <Templates>
  10:        <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
  11:      </Templates>
  12:      <CommandDefinitions>
  13:        <CommandDefinition Id="javascript.Command">
  14:          <EnableRules>
  15:            <EnableRule Id="Mscrm.Enabled"/>
  16:          </EnableRules>
  17:          <DisplayRules />
  18:          <Actions>
  19:            <JavaScriptFunction
  20:                Library="$webresource:new_dialogjavascript"
  21:                FunctionName="callDialog">
  22:            </JavaScriptFunction>
  23:          </Actions>
  24:        </CommandDefinition>
  25:      </CommandDefinitions>
  26:      <RuleDefinitions>
  27:        <TabDisplayRules />
  28:        <DisplayRules />
  29:        <EnableRules />
  30:      </RuleDefinitions>
  31:      <LocLabels />
  32:    </RibbonDiffXml>
  • “CustomAction” tag define the location of the button ( which entity, which group, sequence etc).
  • “Button” tag defines the text, images, tooltip of the button. The most import attribute of “Button” tag is “Command”. In this solution Command = javascript.Command.
  • “CommandDefinition” tag defines the javascript.Command mentioned in “Button” tag.
  • <EnableRule Id="Mscrm.Enabled"/> this line makes the button enabled on the ribbon.
  • “Actions” tag defines which JavaScript webresource and which function in that webresource will be called on button click.
Note: If you already a custom app ribbon button in your solution and you import any other unmanaged solution with “Application Ribbon” file in it. it will over write your custom button. Take a backup of your solution before you import any unmanaged solution.
    function getOrg() {
        ///<summary>
        /// get organisation
        ///</summary>
      
        var Org = "";
        if (typeof GetGlobalContext == "function") {
            var context = GetGlobalContext();
            Org = context.getOrgUniqueName();
        }
        else {
            if (typeof Xrm.Page.context == "object") {
                Org = Xrm.Page.context.getOrgUniqueName();
            }
            else
            { throw new Error("Unable to access Organisation name"); }
        }
       
        return Org;
    }

    function getUser() {
        ///<summary>
        /// get logged in user
        ///</summary>
      
        var User = "";
        if (typeof GetGlobalContext == "function") {
            var context = GetGlobalContext();
            User = context.getUserId();
        }
        else {
            if (typeof Xrm.Page.context == "object") {
                User = Xrm.Page.context.getUserId();
            }
            else
            { throw new Error("Unable to access the UserId"); }
        }
      
        return User;
    }

    function callDialog() {
    
    var url="/" + getOrg() + "/cs/dialog/rundialog.aspx?DialogId=%7bB7D825D7-7EF6-4713-AC11-284546FEB260%7d&EntityName=systemuser&ObjectId=" + getUser();
    window.open(url, "", "status=no,scrollbars=no,toolbars=no,menubar=no,location=no");
    //window.open(url);

    }
The JavaScript Webresource has three function
  • getOrganisation() – to get context organisation
  • getUser()-to get the logged in user
  • callDialog()- will call the dialog. you can change the DialogId to call your own dialog.
This example is using a dialog attached to the user entity, so we don’t need to create any record to run the dialog. The code picks up the logged in user and run the process.
Sales Call Dialog

Sales Call dialog is very simple but meaningful dialog process. Steps are as follow.
  1. Ask for customers first name and last name
  2. Ask if customer exist in the system
    • Search for the customer
  3. Else ask for address information
  4. Ask for the product customer is interested in
  5. Ask if sales rep want to create relevant records. if sales rep select yes create the contact and/or opportunity records.

Note: This dialog does not add product to the opportunity.

Here are some screen shots

image


 
image

 
image

 
Bye…………...