How to read XML file in Dynamics CRM 2011 using Javascript.

In Dynamics CRM 2011, we could maintain the XML files using web resource utility, which is a very good feature. It could be read using Javascript which is also maintained in the web resources of Dyanmics CRM 2011.You could make use of this feature when you want to populate some values dynamically.

Sample xml file –Configuration.xml
<Configurations>
<Configuration id=”Code”>C0001</Configuration>
<Configuration id=”Name”>WebName</Configuration>
</Configurations>

Javascript sample code to read XML File:

var xmlPath = "../WebResources/Configuration.xml";

var xmlnodePath = "//Configurations/Configuration";
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.preserveWhiteSpace = true;
xmldoc.async = false;
xmldoc.load(xmlPath);
var params = new Array();
var xmlnodelist;
xmlnodelist= xmldoc.selectNodes(xmlnodePath);
for (var i = 0; i < xmlnodelist.length; i++)
{
     params[i] = xmlnodelist(i).attributes[0].value;
}
Posted in MS CRM 2011 | Tagged , , | Leave a comment

How to retrieve the Selected Record Ids of a subgrid in Dynamics CRM 2011 using Javascript.

To retrieve the selected records of a subgrid in dynamics crm 2011 just write down below code in your javascript function.

var accountContactsGrid= document.getElementById("accountContactsGrid").control;
var selectedids = gridControl.get_selectedIds();
Posted in MS CRM 2011 | Tagged , , | Leave a comment

How to retrieve current User Id in Dynamics CRM 2011 using Javascript.

Only you need to write below code in your javascript function to get current user Id:

var currentUserId = Xrm.Page.context.getUserId();
Posted in MS CRM 2011 | Tagged , | Leave a comment

How to decide IFD deployment of Dynamics CRM 2011 Environment?

When Dynamics CRM 2011 was released, most deployments were strictly on-premise deployments with access restricted to users on the company network or VPN. However, with the changing landscape of how people work, the consumerization of IT, and the upcoming changes in Dynamics CRM 2011 R8 (cross-browser support and mobile applications), most of our customers are now more closely evaluating their options for giving users external access to the application, including access on mobile devices. They must weigh these enhancements in light of their security policies and what their users are requesting.
There is a list of the most common external access scenarios, and whether or not IFD is required in these scenarios. Please note that deploying Dynamics CRM 2011 IFD will enable any of the options on this list; however, if for some reason you are not prepared for ADFS+ IFD, or if ADFS does not fit within your security strategy, the following table should help you clarify if your external access scenario will require IFD.

misc3

Posted in MS CRM 2011 | Tagged , | Leave a comment

How to create a thread by using C# to show Progress Bar in Window Application

1. Start Microsoft Visual Studio .NET.
2. Create a new Visual C# Windows Application project named ThreadWinApp.
3. Add a Button control to the form. By default, the button is named Button1.
4. Add a ProgressBar component to the form. By default, the progress bar is named ProgressBar1.
5. Right-click the form, and then click View Code.
6. Add the following statement to the beginning of the file:

using System.Threading;

7. Add the following Click event handler for Button1:

private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("This is the main thread");
}

8. Add the following variable to the Form1 class:

private Thread trd;

9. Add the following method to the Form1 class:

private void ThreadTask()
{
int stp;
int newval;
Random rnd=new Random();
while(true)
{
stp=this.progressBar1.Step*rnd.Next(-1,2);
newval = this.progressBar1.Value + stp;
if (newval > this.progressBar1.Maximum)
newval = this.progressBar1.Maximum;
else if (newval < this.progressBar1.Minimum)
newval = this.progressBar1.Minimum;
this.progressBar1.Value = newval;
Thread.Sleep(100);
}
}

Note This is the code that underlies the thread. This code is an infinite loop that randomly increments or decrements the value in ProgressBar1, and then waits 100 milliseconds before it continues.
10. Add the following Load event handler for Form1. This code creates a new thread, makes the thread a background thread, and then starts the thread.

private void Form1_Load(object sender, System.EventArgs e)
{
Thread trd = new Thread(new ThreadStart(this.ThreadTask));
trd.IsBackground = true;
trd.Start();
}
Posted in General | Tagged , , , | 1 Comment

How to pass parameters and get return values for Multithreaded Procedures using C#

Supplying and returning values in a multithreaded application is complicated because the constructor for the thread class must be passed a reference to a procedure that takes no arguments and returns no value.

Parameters for Multithreaded Procedure

The best way to supply parameters for a multithreaded method call is to wrap the target method in a class and define fields for that class that will serve as parameters for the new thread. The advantage of this approach is that you can create a new instance of the class, with its own parameters, every time you want to start a new thread. For example, suppose you have a function that calculates the area of a triangle, as in the following code:

public class AreaClass
{
    public double Base;
    public double Height;
    public double Area;
    public void CalcArea()
    {
        Area = 0.5 * Base * Height;
        MessageBox.Show("The area is: " + Area.ToString());
    }
}

protected void TestArea()
{
    AreaClass AreaObject = new AreaClass();
    System.Threading.Thread Thread =
        new System.Threading.Thread(AreaObject.CalcArea);
    AreaObject.Base = 30;
    AreaObject.Height = 40;
    Thread.Start();
}

Returning values from Multithreaded Procedure

Returning values from procedures that run on separate threads is complicated by the fact that the procedures cannot be functions and cannot use ByRef arguments. The easiest way to return values is to use the BackgroundWorker component to manage your threads and raise an event when the task is done, and process the results with an event handler.
The following example returns a value by raising an event from a procedure running on a separate thread:

class AreaClass2
{
    public double Base;
    public double Height;
    public double CalcArea()
    {
        // Calculate the area of a triangle. 
        return 0.5 * Base * Height;
    }
}

private System.ComponentModel.BackgroundWorker BackgroundWorker1
    = new System.ComponentModel.BackgroundWorker();

private void TestArea2()
{
    InitializeBackgroundWorker();

    AreaClass2 AreaObject2 = new AreaClass2();
    AreaObject2.Base = 30;
    AreaObject2.Height = 40;
    // Start the asynchronous operation.
    BackgroundWorker1.RunWorkerAsync(AreaObject2);
}

private void InitializeBackgroundWorker()
{
    // Attach event handlers to the BackgroundWorker object.
    BackgroundWorker1.DoWork +=
        new System.ComponentModel.DoWorkEventHandler(BackgroundWorker1_DoWork);
    BackgroundWorker1.RunWorkerCompleted +=
        new System.ComponentModel.RunWorkerCompletedEventHandler(BackgroundWorker1_RunWorkerCompleted);
}

private void BackgroundWorker1_DoWork(
    object sender,
    System.ComponentModel.DoWorkEventArgs e)
{
    AreaClass2 AreaObject2 = (AreaClass2)e.Argument;
    // Return the value through the Result property.
    e.Result = AreaObject2.CalcArea();
}

private void BackgroundWorker1_RunWorkerCompleted(
    object sender,
    System.ComponentModel.RunWorkerCompletedEventArgs e)
{
    // Access the result through the Result property. 
    double Area = (double)e.Result;
    MessageBox.Show("The area is: " + Area.ToString());
}
Posted in General | Tagged , | Leave a comment

How to configure mobile express in Dynamics CRM 2011

Mobile Express is installed by default at no extra cost. In Dynamics CRM 2011 the Mobile Express configuration exists within each entity.

For example, if you want to enable Accounts for Mobile Express, go to Settings –> Customization –> Customize the System –> click on the Account entity, and make sure that the checkbox for Mobile Express is checked:
mobile1
Then, navigate to Forms underneath the entity and find the mobile form:
mobile2
Open the form and select the fields you want to appear within Mobile Express and remove unnecessary ones.
mobile3
Publish your changes and test on your mobile device by entering the URL of your organization of Dynamics CRM 2011 with a “/m” after the URL (example: https://amarp.crm.dynamics.com/m)

Posted in MS CRM 2011 | Tagged , | Leave a comment

How to write basic Plugin in Microsoft Dynamics CRM 2011.

A plug-in is custom business logic that you can integrate with Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online to modify or augment the standard behavior of the platform. Plug-ins are event handlers since they are registered to execute in response to a particular event being fired by the platform.

Plug-ins are custom classes that implement the IPlugin interface. You can write a plug-in in any .NET Framework 4 CLR-compliant language such as Microsoft Visual C# and Microsoft Visual Basic .NET. To be able to compile plug-in code, you must add Microsoft.Xrm.Sdk.dll and Microsoft.Crm.Sdk.Proxy.dll assembly references to your project. These assemblies can be found in the SDK\Bin folder of the SDK download.

using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;

namespace Microsoft.Crm.Sdk.Samples
{
    public class SamplePlugin: IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = 
                (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            // Get a reference to the Organization service.
            IOrganizationServiceFactory factory = 
                (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(context.UserId);
            try
            {
                // Plug-in business logic goes below this line.
                // Invoke organization service methods.
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                // Handle the exception.
            }
        }
    }

Each plug-in assembly must be signed, either by using the Signing tab of the project’s properties sheet in Microsoft Visual Studio 2010 or the Strong Name tool, before being registered and deployed to Microsoft DynamicsCRM. For more information about the Strong Name tool, run the sn.exe program, without any arguments, from a Visual Studio 2010Command window.

Posted in MS CRM 2011 | Tagged , | 1 Comment

How to use Early Binding and LINQ to query entity details in Dynamics CRM 2011

Early Binding
The CRMSvcUtil can generate the LINQ Service Context by providing the optional tag:
/serviceContextName:CrmDataContext

The LINQ Service Context that is produced by taking this approach is a gateway to the work with the LINQ provider. When the CRMDataContext class is instantiated, an instance of the Organization Service will be passed:

var = new CrmDataContext(orgServiceInstance)

This produces a LINQ context that code can work with. This context has public, queryable properties for each entity set.
Querying Data with LINQ
Similar to other querying techniques such as QueryExpression, FetchXML, and the use of Filtered Views, LINQ can be used to query data within Microsoft Dynamics CRM 2011.

OrganizationServiceContext orgContext = new OrganizationServiceContext(_service);
 var queryx = from c in orgContext.ContactSet
 join a in orgContext.AccountSet
 on c.ContactId equals a.PrimaryContactId
 select new { contact_name = c.Fullname, account_name = a.Name };
 foreach(var c in queryx)
 {
 this.comboBox2.Items.Add(c.contact_name);
 }

One of the key aspects of LINQ which differentiates it from the two other querying methods is that it can perform record creation, updating, and deleting.

Posted in MS CRM 2011 | Tagged , , | Leave a comment