Muhammad Ali Khan

MS CRM 3.0, MS CRM 4.0, Sharepoint 2007 & Sharepoint 2010

Archive for the ‘MS CRM 3.0’ Category

Show The Associated View On CRM Entity Load

Posted by Ali Khan on February 16, 2010

Hello, Today i just want to share a small MS CRM JavaScript. As we know once any MS CRM Entity form load, the default view is the “Information” view of the entity, as see below for my account form.

image

What if i want to “Quotes” grid to appear as soon as the Account form is open. Well its really one line of JavaScript (First find the id of the left navigation node, thanks to the IE8, it is very easy now, press F12 to launch the debugger tools, find the element by “Search element by Click” option and there you have the element id as shown below)

image

So here is the script for the form OnLoad() event.

  1: if(crmForm.FormType == 2)
  2: {
  3:   document.getElementById('navQuotes').click();
  4:   document.getElementById('_NA_Info').click();
  5: }

and here is how my “Account” form once it loads( i also collapsed the “Details Node” for better view ability). Now once i double click any account in my main grid, by defaults, it loads the “Associated Quotes View” of the “Account”.

image

That’s all.

Advertisements

Posted in MS CRM 3.0, MS CRM 4.0 | Tagged: | 1 Comment »

Relating/Connecting MS CRM 4.0 Data With Custom External Content Type Data In SharePoint 2010

Posted by Ali Khan on February 4, 2010

In this post, i will first display the data from MS CRM 4.0 and from my custom external type(SQL Server Database) in my SharePoint 2010 portal and then show you how to relate(connect) these two different external content type. I got this idea from the “Fabain Williams SharePoint” blog from here SharePoint 2010 Business Connectivity Services Teaser with Multiple External Content Types surfacing in One External List.

As i saw the above post, i thought i could use it to solve my old problem in SharePoint 2007 :). I remember last year one of my customer asked me to display and relate the data from MS CRM 4 and Axapta on SharePoint portal and i end up writing my own custom Web part, since there exits no relationship between these two external content type in MOSS 2007.

Note:- There exits NO PHYSICAL RELATIONSHIP between the two external content type i am going to use below. So here we go:-

Step 1: Setup the MS CRM Account External Content Type:-

First i have to setup my external content type to fetch data from MS CRM 4. I already did that in one of my earlier post. You can see the complete post here (Using Business Connectivity Services(BCS) In SharePoint 2010 For Connecting To MS CRM 4.0). Here is how MS CRM Accounts look like. (The important field to note here is the “AccountNumber” since we will be relating the two external content type on this column).

image

Step 2: Setup the Other External Content Type(SQL Server Database):-

I then created another “External Content Type”, this time to a SQL Server Database, for this you can use this post from Microsoft (How to: Create an External Content Type Based on a SQL Server Table).

Here is how my table(CompanyProjects) in custom database look like. This tables contains the list of the projects against a particular MS CRM Account. As you can see i have put the AccountNumber field in both “MS CRM External Content Type” (above) and in my custom (CompanyProjects) table below, since we will be relating(connecting) the data from these two different source on this field.

image

and here is the data i manually put in.

image

The next step is to create the external content type for the above table( you can do it by following the steps here How to: Create an External Content Type Based on a SQL Server Table). And then i created a SharePoint 2010 List for this external content type, see below. (The important field to note here is the “AccountNumber” since we will be relating the two external content type on this column).

image

Step 3:- Create the “Site Page” which will host these two external content type:-

Go to Site Actions ==> New Page. A New Page Dialog will popup. Name the page and click create.

image

It will open the page in the design mode, now we will insert our two external content type. Click on the “Insert” ribbon, and then click on the “Existing List” button. Select “MS CRM Accounts” list and then click add.

image

image

Here is it how it looks like now. (Note by default the view of the WebPart will be show only the BDC Identity, Edit the WebPart and select the view to your desired view). Note the “AccountNumber” in the below view.

image

Similarly, click on the add “Existing List” button and add the “My Custom Projects” list this time. The whole page will now look like this. Note again the “AccountNumber” in the list.

image

As you can see, both our MS CRM Account and our other external content type (Projects) are on the page now, showing the complete data from both the list. Now the final step is to relate/connect these two lists.

Step 4:- Relate/Connect the Two External Content Type:-

In the SharePoint 2010 portal, Click “Page” ribbon and then from the “Edit” dropdown, select “Edit in SharePoint 2010” Designer, this will open the page in “SharePoint 2010” designer.

Once in SharePoint 2010 designer, select the “MS CRM Account” web part and click “Add Connection” in the ribbon.

image

Now we will create the relationship (well its not really a relationship, its just a connection) between the two WebParts below. A wizard will startup, here is the step by step process to create this connection.

image

image

image

image

Make sure you select the correct columns while defining this connect from both list (i.e. AccountNumber)

A connection between two webparts is now setup. Save the Page in SharePoint 2010 designer, and the open the page in the browser. Here is how the page now looks like. Click on any MS CRM Account Row (Click on image ICON to select the row)

image

image

You can see now the “Project List” is now filtered on the MS CRM Account you selected from the above List (Based on the “Account Number”).

All i can say “Coooooool”. i remembered i had to write a custom WebPart for this to happen in SharePoint 2007.

Actually, i didn’t stop here :), in fact i created one more relationship between my “Custom Projects” and the details of the Tasks “Task List”. so my projects will be filtered on the selected “MS CRM Account” and then my “Tasks” list will be filtered on my selected “Custom Project”. Here is how it looks like. (i am sure you can follow and repeat the above steps to achieve this).

image

So the connection between MS CRM Account and Custom Project is on “AccountNumber” and the connection between “Custom Project” and “Task List” is on “ProjectId”.

Finally, does it means, we don’t have to create our own WebPart for displaying related data from two different “External Content Type”. Well off course not, SharePoint 2010 does provide you a very good platform for connecting non-related “External Content Type” with features of sorting, filtering, creating custom views with basically no code. But there may still exits scenarios where you have to create your own WebPart.

That’s all for now.

Posted in BCS, Bussiness Connectivity Services, MS CRM 3.0, MS CRM 4.0, Sharepoint 2010, SharePoint 2010 Designer, Sharepoint Foundation 2010 | Tagged: | 3 Comments »

Add More Values to Duration(Drop-Down) In MS-CRM 4.0 Task Entity

Posted by Ali Khan on January 24, 2010

In this small post, i will show you how to add more options(Values) to the Standard “Duration” drop-down in the “Task” Entity. So, out of the box, the “Duration” field on the “Task” entity look like this.

image

Note:- “Duration” Field is not a MS CRM Pick-List. It is editable and user can add anything e.g. “4 Days”, “52 Minutes” etc. In fact the data type of the “Duration” field is “Integer”. but in Task entity it looks like a Standard MS CRM Pick list. In-Background MS CRM is generating a table for this field and displaying the values in the drop-down. See the attribute description below:-

image

So to add more values to the “Duration” drop-down, put the following JavaScript code in the Task Entity Form ==> OnLoad() event, save the form and publish the “Task” entity. The code is simply adding rows to the table, which is used to display the “Duration” drop-down on “Task” Entity Form.

var obj = document.getElementById('actualdurationminutesSelect');
var tbl = obj.childNodes[1];
var lastRow = tbl.rows.length;
var row = tbl.insertRow(lastRow);
var cell = row.insertCell(0);
cell.val = '4 days';
cell.innerText = '4 days';
lastRow++;
row = tbl.insertRow(lastRow);
var cell = row.insertCell(0);
cell.val = '5 days';
cell.innerText = '5 days';

After publishing the “Task” entity, the “Duration” drop-down now look like this, with values “4 days” & “5 days” coming inside the default drop-down.

 image

That’s all folks !!!

Posted in MS CRM 3.0, MS CRM 4.0 | Tagged: | 3 Comments »

Using XmlHttp or Ajax With MS CRM 4.0

Posted by Ali Khan on July 21, 2009

In this post i will show you how to use the XmlHTTP Object with MS CRM 4.0 in javascript. Thanks to my project of Zoomio. I have played a lot with XmlHttp object & Javascript .

So here is how we will start…

Add a new tool bar button to the custom entity  “contact” entity, this button once clicked will open the account lookup dialog (as shown below). Once clicked on “ok”, we will update the contact entity’s mobile no and bussiness phone no from the mobile & business phone no of the account.

2

 

So here is the javascript code to be put in the ISV.Config File.

if(crmForm.IsDirty)

{

alert(‘Please Save the Contact before updating the Phone No’);

}

else

{

var str = window.showModalDialog(‘/MicrosoftCRM/_controls/lookup/lookupsingle.aspx?class=null&objecttypes=1&browse=0&DefaultType=0′,”,’dialogHeight: 450px; dialogWidth: 600px; edge: Raised; center: Yes; resizable: Yes; status: Yes;’);

                             

      if(str!=null)

      {

            if(str.items.length>0)

            {

                  var accountID = str.items[0].id;

                  var contactID = crmForm.ObjectId;

                                         

var forwardPath = ‘http://localhost/MyAjaxApp/ajax_page.aspx?contactID=’ + contactID + ‘&accountID=‘ + accountID;

                                         

var objXMLHTTP=new ActiveXObject(‘Microsoft.XMLHTTP’);

  

                  objXMLHTTP.Open(‘POST’,forwardPath,false);

                                         

                  objXMLHTTP.Send(”);

                                         

                  var response=objXMLHTTP.ResponseText;

                  if(response==’success’)

                        window.location.reload(true);

            }

      }

}

And here is the complete xml of the contact entity.

<Entity name=contact>

<ToolBar ValidForCreate=0 ValidForUpdate=1>

            <Button Icon=/_imgs/ico_18_debug.gif

            JavaScript=

                        if(crmForm.IsDirty)

                        {

alert(‘Please Save the Contact before updating the Phone No’);

                             

                        }

                        else

                        {

var str = window.showModalDialog(‘/MicrosoftCRM/_controls/lookup/lookupsingle.aspx?class=null&amp;objecttypes=1&amp;browse=0&amp;DefaultType=0′,”,’dialogHeight: 450px; dialogWidth: 600px; edge: Raised; center: Yes; resizable: Yes; status: Yes;’);

                             

                              if(str!=null)

                              {

                                    if(str.items.length>0)

                                    {

                                          var accountID = str.items[0].id;

                                          var contactID = crmForm.ObjectId;

                                         

                                    var forwardPath = ‘http://localhost/MyAjaxApp/ajax_page.aspx?contactID=&#8217; + contactID + ‘&amp;accountID=’ + accountID;

  

var objXMLHTTP=new ActiveXObject(‘Microsoft.XMLHTTP’);

                                                                 

objXMLHTTP.Open(‘POST’,forwardPath,false);

                                         

                  objXMLHTTP.Send(”);

                                         

                  var response=objXMLHTTP.ResponseText;

                  if(response==’success’)

                        window.location.reload(true);

                                    }

                              }

                        }

                       

                        PassParams=1 WinParams=“” WinMode=1>

                                <Titles>

                                      <Title LCID=1033 Text=Update Phone No />

                                </Titles>

                          </Button>

                          <ToolBarSpacer />

                    </ToolBar>

              </Entity>

You many notice the char &amp; for the ampersond (&) character in the javascript xml, this is to avoid the parsing error in xml.

Now create an asp.net applicaton and name it as “MyAjaxApp”, create an “ajax_page.aspx”. Remove all the code from the aspx page with only this line remaining

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”ajax_page.aspx.cs” Inherits=”ajax_page” %>

Now open the “ajax_page.aspx.cs” file and write the following code in page_load method.

CrmAuthenticationToken token = new CrmAuthenticationToken();

token.AuthenticationType = intAuthenticationType;

token.OrganizationName = strOrganizationName;

  

CrmService objService = new CrmService();

objService.Url = strService;

objService.CrmAuthenticationTokenValue = token;

objService.UseDefaultCredentials = true;

objService.Credentials= System.Net.CredentialCache.DefaultNetworkCredentials;

string accountID = Request.QueryString[“accountID”];

string contactID = Request.QueryString[“contactID”];

 

// first reterive the account entity.

ColumnSet cols = new ColumnSet();

cols.Attributes = new string[] { “telephone1”, “telephone2” };

account objAccount = (account)objService.Retrieve(EntityName.account.ToString(), new Guid(accountID), cols);

 

contact objContact = new contact();

objContact.contactid = new Key();

objContact.contactid.Value = new Guid(contactID);

objContact.telephone1 = objAccount.telephone1;

objContact.telephone2 = objAccount.telephone2;

 

objService.Update(objContact);

Response.Write(“success”);

 

That’s All !!!

Posted in MS CRM 3.0, MS CRM 4.0 | Tagged: | Leave a Comment »

Using MS CRM 3.0 Lookup Form In Your Asp.Net Application

Posted by Ali Khan on November 28, 2007

In this post, I am going to show you how to use the MS CRM 3.0 Lookup form in your application.

So first, here how the MS CRM 3.0 Lookup form looks like

lookup.jpg

Now with only few lines of javascript code you will be able to use this form in your application.

 so here is the sample javascript code J <html>
<head>
    <script language=”javascript”>
        function LookupArgsClass()
        {
            this.items = null;
        }
       
        function openWindow()
        {
            //debugger;
            //var sPath=’_controls/lookup/lookupsingle.aspx?class=null&objecttypes=2&browse=0&DefaultType=0′;
            var sPath=’/_controls/lookup/lookupsingle.aspx?class=ActivityRegarding&objecttypes=1,2,3,4,112,1010,1084,1088&browse=0&DefaultType=2′
            var args = new LookupArgsClass();
            args.items = document.getElementsByTagName(“SPAN”);
            var sCustomWinParams = “dialogWidth:600px0px;dialogHeight:488px0px;dialogLeft=0px;dialogTop=0px;help:0;status:0;scroll:0;center:1;resizable:yes;”
            var abc = window.showModalDialog(sPath,args,sCustomWinParams);
            alert(abc);
        }
    </script>
</head>
<body>
    <input type=”button” onclick=”openWindow()” value=”Click here…”/>
</body>
</html>

 In my other post i am going to show you how to create a lookup like MS CRM 3.0 in your own asp.net application

Posted in MS CRM 3.0 | 2 Comments »

Reterive Mutliple Dynamic Entity Using Attribute Other than ID

Posted by Ali Khan on November 22, 2007

A lot of examples related to DynamicEntity uses either Create, Update or Retrieve (Single). What I was looking for was to retrieved multiple Dynamic Entity but searching on other attributes other than ID, but with no success

So I decided to write it myself J

Here is the sample code of my finding:-

            CrmService service = new CrmService();
            service.Credentials = System.Net.CredentialCache.DefaultCredentials;

            QueryByAttribute query = new QueryByAttribute();
            query.ColumnSet = new AllColumns();
            query.EntityName = “account”;  // please mention your entity name here

            query.Attributes = new string[] { “name” };   // your attribute here.
            query.Values = new string[] { “geopaq” };    // your attribute value here.

            RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
            retrieve.ReturnDynamicEntities = true;
            retrieve.Query = query;

            RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(retrieve);
            foreach (DynamicEntity entity in response.BusinessEntityCollection.BusinessEntities)
            {
                Console.WriteLine(“Entity name=” + entity.Name);
                foreach (Property property in entity.Properties)
                {
                    if (property is CrmBooleanProperty)
                    {
                        CrmBooleanProperty bProperty = property as CrmBooleanProperty;
                        Console.WriteLine(“Property Name=” + bProperty.Name + “value=” + bProperty.Value.Value);
                    }
                    else if (property is CrmDateTimeProperty)
                    {
                        CrmDateTimeProperty dateTimeProperty = property as CrmDateTimeProperty;
                        Console.WriteLine(“Property    Name=” + dateTimeProperty.Name + “value=” + dateTimeProperty.Value.Value.ToString());
                    }
                    else
                    {
                        // similarly put other if statements for other properties here…
                    }
                }
            }

Posted in MS CRM 3.0 | Leave a Comment »