Monday, 29 October 2012

Dynamics Ax - Update using AIF | Get Document Hash

Generate <_DocumentHash> while updating data thru AIF

In Dynamics Ax, version 2009 onwards Document hash is mandatory to update the records using AIF.

When you read data, AIF returns a document hash field. This field contains a hash of all the RecId and RecVersion values for each record that is returned. When you send the data back into AIF to update a record, it recalculates the document hash from the database records in the update and compares it to the document hash in the inbound message. If the data has changed, for example, if a record was updated or added, the calculated document hash will differ from the document hash in the inbound document and AIF will return an error.

When you use the document hash, you only have to read and submit one field for comparison instead of reading and submitting the RecId and RecVersion values for each record. However, if a concurrency error occurs when you use the document hash, AIF can only report that a record was changed and not which record changed.

While implementing some of the scenarios we may even need to perform update in 1 step this could be only possible when are able to generate <_DocumentHash> using X++. Below code describes same.
I have created a test class which extends to AxdBaseRecordInfo and have created one method. In the method I am passing a recId for LedgerJournalTrans and it should return documenthash.
class MyHashCode  extends AxdBaseRecordInfo
{

}

public static str getHashCode(RecId     _recId)
{
    AxdBaseUpdate           axdBaseUpdate = AxdbaseUpdate::construct();
    Map                          dataSourceMap;
    Query                       query = new Query(QueryStr(AxdLedgerGeneralJournal));
    AxdBaseRecordInfo      topAxdBaseRecordInfo;
    QueryRun                  _queryRun;
    str                           documentHash;
    QueryBuildRange         qr;
    LedgerJournalTrans     ledgerJournalTrans;
    RecId                        recId;

    ;
    recId                       = _recId;
    
    select firstOnly ledgerJournalTrans
        where ledgerJournalTrans.RecId == recId;

    dataSourceMap               = new Map(Types::Integer,Types::Integer);
    
    axdbaseUpdate.buildDataSourceParentMap(dataSourceMap, query.dataSourceNo(1)) ;
    query.dataSourceNo(1).addRange(fieldnum(LedgerJournalTrans, RecId)).value(queryValue(recId));

    topAxdBaseRecordInfo        = new AxdBaseRecordInfo(ledgerJournalTrans,1,dataSourceMap);
    documentHash                = topAxdBaseRecordInfo.getRecordHash();

    return documentHash;

}

Job
static void generateDocHash(Args _args)
{
    ;

    info(MyHashCode::getHashCode(5637158049));
}


Above code has been designed to support AX 2012 changes, if you are looking how to perform same in AX 2009 then follow :

AX 2012 client calendar lookups are not taking local system regional setting


We had seen a strange design change in AX 2012 Client calendar lookups.
To give you a brief, up till AX 2009 we AX client Calendar will be taking the local client system setting
Mean to say if we go to windows>> change date and time settings and change the first day of the week as Monday. My expectation , or I would like to put it this way , In AX 2009 if I do this modification and open my Ax client and then go to any of the date field and click Calendar lookup then I should be able to see the calendar for this month starting with day as Monday.
But unfortunately this behavior is not the same in AX 2012 even if we change the regional settings AX client will not take this in to consideration when it is showing calendar lookup. As below
 
The reason for this behavior change is because of the code modification in following class.
\Classes\Global\firstDayOfWeek
Existing code take this information based on DateTimeFormat Info of System.Globalization.DateTimeFormatInfo from assembly mscorlib which is culture independent.
Due to this clientFirstDayOfWeek will always return as 6 which will be always Sunday.
Well work around to this issue could be to us the local registry entry through winAPI as below.
static int firstDayOfWeek()
{
#WinAPI
;
return str2int(WinAPI::getLocaleInfo(#LOCALE_USER_DEFAULT, #LOCALE_FIRSTDAYOFWEEK));
}

Friday, 19 October 2012

Microsoft Announces Winners and Finalists of the 2012 Partner of the Year Awards


REDMOND, Wash. — June 25, 2012 — Microsoft Corp. today announced the winners and finalists of the 2012 Microsoft Partner of the Year Awards. The annual awards honor Microsoft partners for delivering innovative solutions during the past year that directly address customer challenges. Award winners and finalists, chosen from nominations from around the world, will be recognized at the 2012 Microsoft Worldwide Partner Conference, the company’s premier annual event for industry partners, July 8–12 in Toronto.
Nearly 3,000 entries were collected from more than 100 countries; the award finalists and winners were selected from a group of nominations based on their commitment to customers, their solution’s market impact and exemplary use of Microsoft technologies. I would like to congratulate the winners and following are the list of Microsoft Dynamics Partner of the Years:


Microsoft Dynamics Cloud Business Excellence Partner of the Year
·         Winner: Zero2Ten
·         Finalist: Pareto Platform Inc.
·         Finalist: Rose Business Solutions Inc.
Microsoft Dynamics CRM Partner of the Year
·         Winner: PowerObjects
·         Finalist: Accenture/Avanade
·         Finalist: Navantis Inc.
·         Finalist: Sonoma Partners
Microsoft Dynamics Distribution Industry Partner of the Year
·         Winner: Blue Horseshoe
·         Finalist: Junction Solutions
·         Finalist: KORUS Consulting
·         Finalist: Sunrise Technologies
Microsoft Dynamics ERP Partner of the Year
·         Winner: INFOMA Software Consulting GmbH
·         Finalist: InterDyn AKA
·         Finalist: KCS.net Holding AG
·         Finalist: mcaConnect
Microsoft Dynamics Financial Services Industry Partner of the Year
·         Winner: Traviata
·         Finalist: AND Project
·         Finalist: Customer Effective
·         Finalist: Veripark
Microsoft Dynamics Manufacturing Industry Partner of the Year
·         Winner: Edgewater Fullscope Inc.
·         Finalist: Armanino Consulting
·         Finalist: Columbus
·         Finalist: Junction Solutions
Microsoft Dynamics Marketplace Solution Excellence Partner of the Year
·         Winner: ClickDimensions
·         Finalist: Armanino Consulting
·         Finalist: InsideView
·         Finalist: proMX GmbH
Microsoft Dynamics Professional Services Industry Partner of the Year
·         Winner: Systems Advisors Group
·         Finalist: Computer Generated Solutions Inc.
·         Finalist: proMX GmbH
·         Finalist: Sable Systems
Microsoft Dynamics Public Sector Partner of the Year
·         Winner: Rock Solid Technologies
·         Finalist: Accenture/Avanade
·         Finalist: Altus Dynamics
·         Finalist: Ti-M
Microsoft Dynamics Retail Industry Partner of the Year
·         Winner: Ignify Inc.
·         Finalist: Cole Systems Associates Inc.
·         Finalist: Manzana Group
·         Finalist: QURIUS PRODWARE SPAIN

Build a Plug-in That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions



This walkthrough demonstrates how to write a simple Microsoft Dynamics CRM 2011 on-premises plug-in that attaches a note to a new contact.
You can find the sample code that this walkthrough produces in the SDK\Walkthroughs\Portals\PluginWalkthrough folder.
noteNote
This walkthrough is for a Microsoft Dynamics CRM 2011 on-premises deployment.

In This Topic

Generate Early Bound Types

  1. Run the CrmSvcUtil.exe tool, with the Microsoft.Xrm.Client.CodeGeneration extension, to generate your entity classes and service contexts. The following is an example command to create a file called Xrm.cs that points at an instance of Microsoft Dynamics CRM. Note that the Microsoft.Xrm.Client.CodeGeneration.dll file must be in the same directory as the CrmSvcUtil.exe file, or in the system GAC, when you run this command.
    CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm\Xrm.cs /url:http://Crm/Contoso/XRMServices/2011/Organization.svc /domain:CONTOSO /username:administrator /password:pass@word1 /namespace:Xrm /serviceContextName:XrmServiceContext
    

Set up your plug-in project in Visual Studio

  1. Create a new class library project in Microsoft Visual Studio as shown here. This sample uses “Plugin” as the project name.
    Create project in Visual Studio
  2. Add the following references from the SDK\bin folder.
    • Microsoft.Xrm.Client.dll
    • Microsoft.Xrm.Sdk.dll
  3. Add the following .NET references.
    • Microsoft.IdentityModel.dll
    • System.Data.Services
    • System.Data.Services.Client
    • System.Runtime.Serialization
    • System.ServiceModel

    If you do not have the Microsoft.IdentityModel.dll file, you must install Windows Identity Foundation.
  4. Right-click the project in Visual Studio, click Add, and then click Existing Item.
  5. Select the “xrm.cs” file that you created when you generated the early bound types.
  6. Right-click your project again, click Add, and then click New Item.
  7. Select Application Configuration File from the options and then click Add.
  8. Edit the configuration file with your specific connection string. For more information, see Simplified Connection to Microsoft Dynamics CRM.

Sign your plug-in project

Add a strong key to your project

  1. Open the properties pane under your plug-in project.
    Open properties pane
  2. Create a new strong key file by clicking the Signing tab, select the Sign the assembly check box and select <New…> in the drop down list.
    Create strong key
  3. Type a name for your strong key (in this example, it is “PluginWalkthrough”) and clear the ”Protect my key file with a password” check box before clicking OK.
    Create a strong name key
  4. Save your changes.

Create the plug-in that will run your code

This plug-in will run when a contact is created. The following code shows how to create the plug-in.
  1. Right-click your project again, click Add, and then click New Item.
  2. Select Class from the options, type the name “Plugin.cs”, and then click Add.
    Create a plugin
  3. Add the following code to the Plugins.cs file:
    using System;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    using Xrm;
    
    public class Plugin: IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {
    IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));
    
    Entity entity;
    
    // Check if the input parameters property bag contains a target
    // of the create operation and that target is of type Entity.
    if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
    {
    // Obtain the target business entity from the input parameters.
    entity = (Entity)context.InputParameters["Target"];
    
    // Verify that the entity represents a contact.
    if (entity.LogicalName != "contact") { return; }
    }
    else
    {
    return;
    }
    
    try
    {
    IOrganizationServiceFactory serviceFactory = 
        (IOrganizationServiceFactory)serviceProvider.GetService(
    typeof(IOrganizationServiceFactory));
    IOrganizationService service = 
    serviceFactory.CreateOrganizationService(context.UserId);
    
    var id = (Guid)context.OutputParameters["id"];
    
    AddNoteToContact(service, id);
    }
    catch (FaultException<OrganizationServiceFault> ex)
    {
    throw new InvalidPluginExecutionException(
    "An error occurred in the plug-in.", ex);
    }
    }
    
    private static void AddNoteToContact(IOrganizationService service, Guid id)
    {
    using (var crm = new XrmServiceContext(service))
    {
    
    var contact = crm.ContactSet.Where(
    c => c.ContactId == id).First();
    Debug.Write(contact.FirstName);
    
    var note = new Annotation
    {
    Subject = "Created with plugin",
    NoteText = "This Note was created by the example plug-in",
    ObjectId = contact.ToEntityReference(),
    ObjectTypeCode = contact.LogicalName
    };
    
    crm.AddObject(note);
    crm.SaveChanges();
    }
    }
    }
    
  4. Build the solution.

Register your plug-in with the Plugin Registration Tool

  1. Add all dependent assemblies to the GAC on the server. To do this, open your project’s Debug/bin folder and copy all *.dll files except for the main PluginWalkthrough.dll file to the GAC on the server.
  2. Build and run the Plug-in Registration tool. You can find the source code for the tool in the SDK\Tools\PluginRegistration folder.
  3. Click Create New Connection.
    Register the plug-in
  4. In the Connections panel, enter a descriptive label for the connection. Fill in the other fields as appropriate for your Microsoft Dynamics CRM server.
  5. Click Connect. A connection to the server is established and a list of available organizations for the specified system account is displayed.
  6. Double-click the desired organization in the connections list. The list of all assemblies, steps, and plug-ins currently registered for the target organization is displayed.
    Browse to your organization's plug-in list
  7. Click Register New Assembly.
    Register new assembly
  8. In the Register New Plugin dialog box, click the ellipsis button (…) and navigate to the location of your plug-in assembly. Select the assembly and make sure that all plug-ins under it are selected.
  9. Select None for the isolation mode. Note that Developer Extensions for Microsoft Dynamics CRM currently does not support the sandbox isolation mode. Verify that the Database option is selected so that the plug-in will be stored in your organization’s database.
  10. Click Register Selected Plugins.
    Register plug-in
  11. Click OK.
    Plug-in registered
  12. Expand the assembly and select the plug-in that you just registered. Select Register, and then click Register New Step.
    Register new step
  13. In the Register New Step dialog box, enter the Microsoft Dynamics CRM message that the step will be registered under. In this example, type “Create”. Under Primary Entity, type “contact”. Leave the Pipeline stage set to Post Stage, execution mode to Synchronous, and other options set to default. Click Register New Step.
    Register new step The registered step appears under the plug-in.
    Step registered successfully
  14. Test the plug-in by creating a new contact in Microsoft Dynamics CRM. After you have saved the entity, a note should be attached.

Build a Web Application That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions


This walkthrough demonstrates how to write a simple Web application that connects to Microsoft Dynamics CRM 2011 and performs a basic create contact transaction.
You can find the sample code that this walkthrough produces in the Sdk\Walkthroughs\Portal\WebAppWalkthrough folder.

In This Topic


Generate Early Bound Types

  1. Run the CrmSvcUtil.exe tool, with the Microsoft.Xrm.Client.CodeGeneration extension, to generate your entity classes and service contexts. The following example command creates a file called “Xrm.cs” that points at an instance of Microsoft Dynamics CRM. Note that the Microsoft.Xrm.Client.CodeGeneration.dll file must be in the same directory as the CrmSvcUtil.exe file, or in the system GAC, when you run this command.
    CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm\Xrm.cs /url:http://Crm/Contoso/XRMServices/2011/Organization.svc /domain:CONTOSO /username:administrator /password:pass@word1 /namespace:Xrm /serviceContextName:XrmServiceContext
    

Set up your Web application project in Visual Studio

  1. Create a new ASP.NET Web application project in Microsoft Visual Studio. This sample uses “WebAppWalkthrough” as the project name.
    Create Web application in Visual Studio
  2. Add the following references from the SDK\bin folder.
    • AntiXSSLibrary.dll
    • Microsoft.Crm.Sdk.Proxy.dll
    • Microsoft.Xrm.Client.dll
    • Microsoft.Xrm.Portal.dll
    • Microsoft.Xrm.Portal.Files.dll
    • Microsoft.Xrm.Sdk.dll
  3. Add the following references from .NET.
    • Microsoft.IdentityModel.dll
    • Microsoft.Data.Entity.dll
    • System.Data.Services.dll
    • System.Data.Services.Client.dll
    • System.Runtime.Caching.dll
    • System.Runtime.Serialization.dll

    If you do not have the Microsoft.IdentityModel.dll file, you must install Windows Identity Foundation.
  4. Right-click the project in Visual Studio, click Add, and then click Existing Item.
  5. Select the “xrm.cs” file that you created when you generated the early bound types.
  6. Edit the web.config file to register the <microsoft.xrm.client> section. You will need to add a section into the configSections node of the configuration as shown here.
    <configuration>
      <configSections>
        <section name="microsoft.xrm.client"
          type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client" />
    
  7. Edit the web.config file with your specific connection string and context. For the connection string, set the name to “Xrm”. In the <microsoft.xrm.client> section add a context with the name “Xrm” and set the type to the namespace and service context name you provided in Step 1 when you set up the Web application project. In the following example it is Xrm.XrmServiceContext and the assembly part of the type is the name of your Web application, “WebAppWalkthrough”.
    <connectionStrings>
      <add name="Xrm" connectionString="Server=http://crm/contoso; Domain=CONTOSO; Username=Administrator; Password=pass@word1" />
    </connectionStrings>
    <microsoft.xrm.client>
      <contexts>
        <add name="Xrm" type="Xrm.XrmServiceContext, WebAppWalkthrough" />
      </contexts>
    </microsoft.xrm.client>
    
  8. Add the following to the <controls> section of the web.config file to register the Microsoft.Xrm.Portal controls with this Web application.
       <system.web>
         <pages>
           <controls>
             <add tagPrefix="crm" namespace="Microsoft.Xrm.Portal.Web.UI.WebControls" assembly="Microsoft.Xrm.Portal" />
    

Create a Web Page – Contact Grid 1

Create a basic Web page that displays all contacts in your Microsoft Dynamics CRM system in an ASP.NET data grid.
  1. Right-click your project and add a new Web form called “WebForm_LinqDataSource.aspx”.
  2. Add the following to the new aspx page:
    <!--This example lists all contacts from the Microsoft Dynamics CRM system. -->
    <asp:LinqDataSource ID="Contacts" ContextTypeName="Xrm.XrmServiceContext" TableName="ContactSet" runat="server" />
    <asp:GridView DataSourceID="Contacts" AutoGenerateColumns="false" runat="server">
        <Columns>
            <asp:TemplateField HeaderText="First Name">
                <ItemTemplate>
                    <asp:Label Text='<%# Eval("firstname")%>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Last Name">
                <ItemTemplate>
                    <asp:Label Text='<%# Eval("lastname")%>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="City">
                <ItemTemplate>
                    <asp:Label Text='<%#Eval("address1_city") %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
  3. Build the project.
  4. Right-click the aspx page and select View in Browser. The results should look something like this:
    View in browser

Create Another Web Page – Contact Grid 2

Create a Web page that displays contacts in your Microsoft Dynamics CRM system in an ASP.NET data grid based on a Microsoft Dynamics CRM view definition.
  1. Right-click your project and add a new Web form called “WebForm_SavedQueryDataSource.aspx”.
  2. Add the following to the new aspx page.
    <crm:SavedQueryDataSource ID="ActiveContacts" SavedQueryName="Active Contacts" runat="server" />
    <asp:GridView DataSourceID="ActiveContacts" runat="server" />
    
  3. Build the project.
  4. Right-click the aspx page and select View in Browser. This page will use the view definition “Active Contacts” to return the records and display the attributes of the view in an ASP.NET GridView control. The results should look something like this:
    View in browser

Create a WCF Data Service

Create a WCF Data Service for Microsoft Dynamics CRM.
  1. Right-click your project and add a new WCF Data Service called “CrmData.svc”:
    Create data service
  2. You need to point the WCF data service at the XrmServiceContext created at the beginning of the walkthrough. Edit the CrmData.svc.cs file as follows:
    namespace WebAppWalkthrough
    {
        public class CrmData : DataService<Xrm.XrmServiceContext>
        {
            // This method is called only once to initialize service-wide policies.
            public static void InitializeService(DataServiceConfiguration config)
            {
                config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
                config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
            }
        }
    }
    

Create a Web Page – Contact Form 1

Create a Web page that renders a Contact data entry form based on a Microsoft Dynamics CRM view definition:
  1. In Microsoft Dynamics CRM, go to Settings, Customizations, and Customize the System. Create a new view for the Contact entity called “Create Contact Web Form”.
    Create a Web page
  2. Add columns to the view that you want to have appear as fields in the generated form.
  3. Click Save and Publish.
  4. Right-click your Web project in Microsoft Visual Studio and add a new Web form called “WebForm_FromSavedQuery.aspx”.
  5. Add the following code to the new aspx page:
    <asp:ScriptManager runat="server" />
    <crm:CrmDataSource ID="Contacts" runat="server" />
    <crm:CrmEntityFormView DataSourceID="Contacts" EntityName="contact" SavedQueryName="Create Contact Web Form" runat="server" />
    
  6. Build the project.
  7. Right-click the aspx page and click View in Browser. The results should look something like this:
    View in browser

Create Another Web Page – Contact Grid 3

Create a Web page that uses code behind to connect a Microsoft Dynamics CRM data source to an ASP.NET GridView control.
  1. Right-click your project and add a new Web page called “WebForm_CodeBehindDataSource.aspx”.
  2. Add the following code to the new aspx page.
    <asp:GridView ID="ContactsGridView" AutoGenerateColumns="false" runat="server">
        <Columns>
            <asp:TemplateField HeaderText="First Name">
                <ItemTemplate>
                    <asp:Label Text='<%# Eval("firstname")%>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Last Name">
                <ItemTemplate>
                    <asp:Label Text='<%# Eval("lastname") %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="City">
                <ItemTemplate>
                    <asp:Label Text='<%# Eval("address1_city") %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    
  3. Edit the code-behind file WebForm_CodeBehind.aspx.cs as follows:
    using System;
    using System.Linq;
    using Xrm;
    
    namespace WebAppWalkthrough
    {
        public partial class WebForm_CodeBehind : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                var xrm = new XrmServiceContext("Xrm");
    
                //Use all contacts where the email address ends in @example.com.
                var exampleContacts = xrm.ContactSet
                    .Where(c => c.EMailAddress1.EndsWith("@example.com"));
    
                ContactsGrid_CodeBehind.DataSource = exampleContacts;
                ContactsGrid_CodeBehind.DataBind();
            }
        }
    }
    
  4. Build the project.
  5. Right-click the aspx page and click View in Browser. The results should look something like this:
    View in browser

How to: Get and Set a Lookup Value in Jscript in Microsoft Dynamics CRM 2011


This is one of those posts that comes from the fact that there are a lot of questions in the forums that relate to this topic and there are a lot of good posts that demonstrate either how to set a lookup value or get a lookup value, but there aren't many that show both.  So that is what we will do today.

Here is a quick demo on how to either get or set a lookup value in Jscript in Microsoft Dynamics CRM 2011:



 //Get a lookup value 
    var lookupItem = new Array(); 
    lookupItem = Xrm.Page.getAttribute("yourAttributeSchemaName").getValue();
 
    if (lookupItem != null) 
    {
 
        var name = lookupItem[0].name; 
        var guid = lookupItem[0].id; 
        var entType = lookupItem[0].entityType;
    }
 

 
 //Set a lookup value
    var value = new Array();
    value[0] = new Object();
    value[0].id = idValue;
    value[0].name = textValue;
    value[0].entityType = typeValue;
    Xrm.Page.getAttribute("yourAttributeSchemaName").setValue(value);
 
 
 //or alternatively you can set it like this
   Xrm.Page.getAttribute("yourAttributeSchemaName").setValue( [{id: idValue, name: textValue, entityType: typeValue}]);

Note: You must wrap your code in a function in CRM 2011 to be called by an event handler.  This is achieved by using the syntax below:

function test()
{
   //my jscript code here!
}

Now you can just call your function name from an event handler by specifying the web resource and the function name "test".

Using JScript to Access SOAP Web Services Synchronously in Microsoft Dynamics CRM 2011


How to work with JScript web services asynchronously using callback mechanisms and such to make thing happen in the UI after the fact.  I just feel that this is the best way to go for MOST operations as it doesn't slow down the UI as much, but I think it is time to let people in on to how to do these sorts of things synchronously in Microsoft Dynamics CRM 2011.

I will use the example of a RetrieveMultiple request for this purpose that retrieves all accounts of a specific name and I can tell you that because the name is specific that this example will only return one result in my system. After I present the code I will break down the differences for you between asynchronous jscript and synchronous jscript calls.

Here is the Code:


if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SAMPLES = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + OrgServicePath;
               }, 
           RetrieveMultipleRequest: function () {
               var requestMain = ""
               requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
               requestMain += "  <s:Body>";
               requestMain += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
               requestMain += "      <request i:type=\"a:RetrieveMultipleRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
               requestMain += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
               requestMain += "          <a:KeyValuePairOfstringanyType>";
               requestMain += "            <b:key>Query</b:key>";
               requestMain += "            <b:value i:type=\"a:QueryExpression\">";
               requestMain += "              <a:ColumnSet>";
               requestMain += "                <a:AllColumns>true</a:AllColumns>";
               requestMain += "                <a:Columns xmlns:c=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\" />";
               requestMain += "              </a:ColumnSet>";
               requestMain += "              <a:Criteria>";
               requestMain += "                <a:Conditions>";
               requestMain += "                  <a:ConditionExpression>";
               requestMain += "                    <a:AttributeName>name</a:AttributeName>";
               requestMain += "                    <a:Operator>Equal</a:Operator>";
               requestMain += "                    <a:Values xmlns:c=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
               requestMain += "                      <c:anyType i:type=\"d:string\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\">TestAccountName</c:anyType>";
               requestMain += "                    </a:Values>";
               requestMain += "                  </a:ConditionExpression>";
               requestMain += "                </a:Conditions>";
               requestMain += "                <a:FilterOperator>And</a:FilterOperator>";
               requestMain += "                <a:Filters />";
               requestMain += "              </a:Criteria>";
               requestMain += "              <a:Distinct>false</a:Distinct>";
               requestMain += "              <a:EntityName>account</a:EntityName>";
               requestMain += "              <a:LinkEntities />";
               requestMain += "              <a:Orders />";
               requestMain += "              <a:PageInfo>";
               requestMain += "                <a:Count>0</a:Count>";
               requestMain += "                <a:PageNumber>0</a:PageNumber>";
               requestMain += "                <a:PagingCookie i:nil=\"true\" />";
               requestMain += "                <a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>";
               requestMain += "              </a:PageInfo>";
               requestMain += "              <a:NoLock>false</a:NoLock>";
               requestMain += "            </b:value>";
               requestMain += "          </a:KeyValuePairOfstringanyType>";
               requestMain += "        </a:Parameters>";
               requestMain += "        <a:RequestId i:nil=\"true\" />";
               requestMain += "        <a:RequestName>RetrieveMultiple</a:RequestName>";
               requestMain += "      </request>";
               requestMain += "    </Execute>";
               requestMain += "  </s:Body>";
               requestMain += "</s:Envelope>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SAMPLES._getServerUrl(), false)
               // Responses will return XML. It isn't possible to return JSON.
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");             
               req.send(requestMain);
               
               //work with response here
               var strResponse = req.responseXML.xml;
               alert(strResponse.toString());
           },
 __namespace: true
};


Using this syntax you would reference the SDK.SAMPLES.RetrieveMultipleRequest namespace in the

You will see that I am alerting the response here, but you will probably want to parse out and work with the response easily using a technique like I illustrate herehttp://mileyja.blogspot.com/2011/03/microsoft-dynamics-crm-2011-parsing.html

Now for the differences in calling web services synchronously:

The biggest difference from a coding standpoint is the req.open method that uses a false parameter for an synchronous call versus a true for an asynchronous call. - shown below


               req.open("POST", SDK.SAMPLES._getServerUrl(), false)



Good and Bad for Asychronous:
- UI isn't hindered by call happening in the background, much better experience from UI standpoint.
- It is difficult to perform manipulations in UI based on the response, especially in a timely manner.

Good and Bad for Synchronous:
 - UI performance hit because UI will stop responding until response is received from call.  This impact could be negligible or catastrophic depending on the performance and latency of the server at any given time.  It also will be impacted based on the type of call.  For instance, a RetrieveAllEntitiesRequest, might take minutes to respond and lock up the UI for that entire period.  Sometimes this call might not return at all.
- It is easy to work with the response and work with the UI in the same thread and manipulate the UI based on the response.