Thursday 26 April 2012

update automatic numbers when the record is updated in dyanmic crm 2011 with plugin

this is the plugin for the record updating.

for this take the preimage and post image.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xrm;
using System.Diagnostics;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Windows.Browser;
using System.Net;
using System.IO;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Client;
namespace super.Plugin.TimeCaluculation
{
   public class TimeCaluculationUpdate:IPlugin
    {
        public int totaltime;

        //public Entity entity1;

        public IOrganizationService service;
        public IPluginExecutionContext context;
        public int time1;
        public int time2;
        public EntityReference slaid;

        public void Execute(IServiceProvider serviceProvider)
        {


            IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            //Entity entity;

            //EntityReference

            // 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)
            {

                if (context.PreEntityImages.Contains("new_item") && context.PreEntityImages["new_item "] is Entity)
                {

                    Entity slaitem = (Entity)context.PreEntityImages[" new_item "];
                    time1 = (int)slaitem.Attributes["new_time"];
                    slaid = (EntityReference)slaitem.Attributes["new_aid"];
                }
                if (context.PostEntityImages.Contains(" new_item ") && context.PostEntityImages[" new_item "] is Entity)
                {
                    Entity slaitems = (Entity)context.PostEntityImages[" new_item "];
                    time2 = (int)slaitems.Attributes["new_time"];

                }


                ColumnSet cols = new ColumnSet(new String[] { "new_maxtime", "new_name" });
                var contact1 = service.Retrieve("new_sss", aid.Id, cols);

                int timeofitems = Convert.ToInt32(contact1["new_maxtime"]);
                totaltime = timeofitems + (time2 - time1);
                contact1["new_maxtime"] = totaltime;
                service.Update(contact1);

            }

            else return;
        }
           

    }
}

updating numbers when delete a record in dynamic crm 2011 by using plugin

create a early bond,
for this require PreImage.

take the preimage and caluculate the value of the field.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xrm;
using System.Diagnostics;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Windows.Browser;
using System.Net;
using System.IO;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Client;

namespace Super.Plugin.TimeCaluculation
{
   public class TimeCaluculationDelete:IPlugin
    {
        public int totaltime;

        //public Entity entity1;

        public IOrganizationService service;
        public IPluginExecutionContext context;

        public void Execute(IServiceProvider serviceProvider)
        {


            IPluginExecutionContext context = (IPluginExecutionContext)
            serviceProvider.GetService(typeof(IPluginExecutionContext));

            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);          

            // 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 EntityReference)
            {

                if (context.PreEntityImages.Contains("new_item") && context.PreEntityImages["new_item"] is Entity)
                {

                    Entity slaitem = (Entity)context.PreEntityImages["new_item"];
                    int time = (int)slaitem.Attributes["new_time"];
                    EntityReference slaid = (EntityReference)slaitem.Attributes["new_laid"];

                    ColumnSet cols = new ColumnSet(new String[] { "new_maxtime", "new_name" });
                    var contact1 = service.Retrieve("slk_sla", slaid.Id, cols);

                    int timeofitems = Convert.ToInt32(contact1["new_maxtime"]);
                    totaltime = timeofitems - time;
                    contact1["new_maxtime"] = totaltime;
                    service.Update(contact1);

                }
            }
            else return;
        }
    }
}

updating numbers in dynamic crm 2011 using plugin

first:
need to take the early bond and add it on existing items
now we can add the references.

if you create a new record then the filed value need to take the amount of field value.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xrm;
using System.Diagnostics;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Windows.Browser;
using System.Net;
using System.IO;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Client;

namespace super.Plugin.TimeCaluculation
{
    public class TimecaluculationCreate : IPlugin
    {
        public int totaltime;

        public Entity entity1;

        public IOrganizationService service;
        public IPluginExecutionContext context;

        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 != "new_item")
                {
                    return;
                }
            }
            else
            {
                return;
            }

            try
            {
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                Entity entity1 = (Entity)context.InputParameters["Target"];
                if (context.MessageName == "Create")
                {
                    int timeonitems = Convert.ToInt32(entity1["new_time"]);
                    EntityReference var1 = (EntityReference)entity1["new_lid"];


                    ColumnSet cols = new ColumnSet(
                                         new String[] { "new_maxtime", "new_name" });

                    var contact1 = service.Retrieve("new_la", var1.Id, cols);

                    if (contact1.Attributes.Keys.Contains("new_maxtime") == false)
                    {
                        totaltime = timeonitems;
                    }


                    else
                    {
                        int timeofitems = Convert.ToInt32(contact1["new_maxtime"]);

                        totaltime = timeofitems + timeonitems;
                    }

                    contact1["new_maxtime"] = totaltime;

                    service.Update(contact1);
                }
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
            }


        }

    }
}

it will update the new_maxtime filed with count.

Tuesday 24 April 2012

Plug is for sending the sms in dynamic crm 2011.

First need to do the early binding and add it to the classlibrary.
then give the required references:

then the coding is:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xrm;
using System.Diagnostics;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Windows.Browser;
using System.Net;
using System.IO;
using System.ServiceModel.Description;

using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Client;





namespace mop.men.SendSMS
{
    public class SendingSms : IPlugin
    {

        public const string AUTHORIZE = "http:\link";

        string ret = null;
        private OrganizationServiceProxy _serviceProxy;

        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 != "new_sms")
                {
                    return;
                }
            }
            else
            {
                return;
            }

            try
            {
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                Entity entity1 = (Entity)context.InputParameters["Target"];

                ColumnSet cols = new ColumnSet(
                                     new String[] { "subject", "new_phonenumber" });

                var contact = service.Retrieve("new_sms", entity1.Id, cols);

                string subjects = contact["subject"].ToString();
                string phonenumber = contact["new_phonenumber"].ToString();

                ret = AUTHORIZE + "?no=" + phonenumber + "&msg=" + subjects;

              //  WebRequest request = WebRequest.Create("your url comes here with parameters and stuf like in IE");
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ret);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                SetStateRequest setStatePhoneCall = new SetStateRequest
                {
                    EntityMoniker = new EntityReference(new_sms.EntityLogicalName, entity1.Id),
                    State = new OptionSetValue((int)slk_smsState.Completed),
                    Status = new OptionSetValue(-1)
                };

                service.Execute(setStatePhoneCall);

                //Console.WriteLine("PhoneCall entity instance has been marked as completed.");

                //PhoneCallState.Completed

            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
            }
        }

    }

}


and register this plug in for the create 

then doing customize in ribbon area for sending button:

<CustomAction Id="ss_SendSMS" Location="Mscrm.Form.new_sms.MainTab.Save.Controls._children" Sequence="1">
            <CommandUIDefinition>
              <Button Id="btn_newSendSMS" Command="Mscrm.RunSomeJS" LabelText="Send SMS" ToolTipTitle="Send SMS" ToolTipDescription="Sends the SMS" TemplateAlias="o1" Image16by16="/_imgs/SFA/SendAsEmail_16.png" Image32by32="/_imgs/SFA/SendAsEmail_32.png" />
            </CommandUIDefinition>
          </CustomAction>


<CommandDefinition Id="Mscrm.RunSomeJS">
            <EnableRules> </EnableRules>
            <DisplayRules />
            <Actions>
              <JavaScriptFunction FunctionName="SendSMS" Library="$Webresource:new_sendingsms"/>
            </Actions>
          </CommandDefinition>


the Java script is : 

function SendSMS()
{
Xrm.Page.data.entity.save("save");
}


Export Ribbon to XML

For this
Goto:
1.sdk\samplecode\cs\client\ribbon\exportribbonxml

then build and run the  exportribbonxml.sln

then we will get the screen like:













then we will get the screen:


if you choose the organization then it will give the xml files of all entity ribbons

we will see this on :

sdk\samplecode\cs\client\ribbon\exportribbonxml\bin\Debug\ExportedRibbonXml

Friday 20 April 2012

Could not load file or assembly ‘Microsoft.IdentityModel,

for this you need to have the wif folder
after that we can place it in :
C:\Program Files\Reference Assemblies\Microsoft
then:
start - all programs - Microsoft visual studio 2010 - visual studio tools -  visual studio command promt (2010).

there : gacutil -I "<sdk bin path>\Microsoft.IdentityModel.dll


ex : gacutil -I E:\sdk\bin\Microsoft.IdentityModel.dll


then it will install.


refer the link: http://www.badguy.nl/2011/08/09/using-crm-2011-developer-toolkit-on-windows-xp/


workflow vs dialogs


Workflows Dialogs 
Asynchronous Synchronous 
Can be triggered by events or run on-demandCannot be triggered by events; always run on-demand
Never require user interaction to completeAlways require user interaction to complete
Can be run on multiple recordsCan only be run on one record at a time
Cannot build interactive queries of CRM data CAN build interactive queries of CRM data


http://www.dynamicscrmtrickbag.com/2011/04/11/dynamic-queries-in-dialog-processes/  for dialogs.

Wednesday 18 April 2012

option set filter in dynamic crm 2011.

 this  is for filter the two optional sets:

ex : new_country attribute have the 4 values : like India, USA, Japan, China
 if you select India, the new_states filed need to show the states belongs to india.

for this we can use this javascript:
place this java script function in Form Properities :
Onchange event of new_country attribute.
 





http://www.magnetism.co.nz/blog/zhenyu/12-01-18/Filter_Option_sets_by_another_field_in_Dynamic_CRM_2011.aspx

http://msdn.microsoft.com/en-us/library/gg334409.aspx

http://msdn.microsoft.com/en-us/library/gg328130.aspx
http://crmbusiness.wordpress.com/2011/02/17/crm-2011-javascript-xrm-page-basics/


refer above link for details:

function PicklistOneOnchange()
{

var optionsetControl = Xrm.Page.ui.controls.get("new_states");
var options = optionsetControl.getAttribute().getOptions();
var type = Xrm.Page.getAttribute("new_country").getValue();
if (type == 852700000)
{
optionsetControl.clearOptions();
for (var i = 0; i <options.length - 1; i++)
{
if (i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6)
{
optionsetControl.addOption(options[i]);
}
}

}

if (type == 852700001)
{
optionsetControl.clearOptions();
for (var i = 0; i < options.length - 1; i++)
{
if (i == 7 || i == 8 || i == 9)
{

optionsetControl.addOption(options[i]);
}

}


}
if (type == 852700002)
{
optionsetControl.clearOptions();
for (var i = 0; i < options.length - 1; i++)
{
if (i == 10 || i == 11 || i == 12 || i == 13 || i == 14 || i == 15)
{

optionsetControl.addOption(options[i]);
}

}


}

if (type == 852700003)
{
optionsetControl.clearOptions();
for (var i = 0; i < options.length; i++)
{
if (i == 16 || i == 17 || i == 18)
{

optionsetControl.addOption(options[i]);
}

}



}
if (type == null )
{

optionsetControl.clearOptions();

for (var i = 1; i < options.length; i++)
{


optionsetControl.addOption(options[i]);


}

}
}


Monday 16 April 2012

getting the GUID of current form

java script:

function showvalue(message,value)
{
prompt(message,value);
}

Pls check the Spellings correctly

<JavaScriptFunction FunctionName="showvalue" Library="$webresource:new_forguid" >
                <StringParameter Value="form guid:"/>
                <CrmParameter Value="PrimaryItemIds"/>
              </JavaScriptFunction>

by using this will get the current opened form id.

Thursday 12 April 2012

creating custom buttons in the account entity home page

<CustomActions>
          <CustomAction Id="Mscrm.HomepageGrid.account.CustomGroup.CustomAction" Location="Mscrm.HomepageGrid.account.MainTab.Groups._children" Sequence="110">
            <CommandUIDefinition>
              <Group Id="Mscrm.HomepageGrid.account.CustomGroup.Group" Command="Mscrm.HomepageGrid.account.CustomGroup.Command" Title="custom groups" Sequence="51" Template="Mscrm.Templates.Flexible2">
                <Controls Id="Mscrm.HomepageGrid.account.CustomGroup.Controls">
                  <Button Id="Mscrm.HomepageGrid.account.CustomGroup.Button.A" Command="Mscrm.HomepageGrid.account.CustomGroup.Button.A.Command" Sequence="100" LabelText="Connect to linkedIn" ToolTipTitle="TipTitle" ToolTipDescription="TipDescription" TemplateAlias="o1" Image16by16="/_imgs/ribbon/newchart16.png" Image32by32="/_imgs/ribbon/newchart32.png" />
                  <Button Id="Mscrm.HomepageGrid.account.CustomGroup.Button.B" Command="Mscrm.HomepageGrid.account.CustomGroup.Button.B.Command" Sequence="120" LabelText="Import Company Details" ToolTipTitle="TipTitle" ToolTipDescription="TipDescription" TemplateAlias="o1" Image16by16="/_imgs/ribbon/CustomEntity_16.png" Image32by32="/_imgs/ribbon/CustomEntity_32.png" />
                  <Button Id="Mscrm.HomepageGrid.account.CustomGroup.Button.C" Command="Mscrm.HomepageGrid.account.CustomGroup.Button.C.Command" Sequence="130" LabelText="Import Contact Details" ToolTipTitle="TipTitle" ToolTipDescription="TipDescription" TemplateAlias="o1" Image16by16="/_imgs/ribbon/CustomEntity_16.png" Image32by32="/_imgs/ribbon/CustomEntity_32.png" />
                </Controls>
              </Group>
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.HomepageGrid.account.CustomGroup.MaxSize.CustomAction" Location="Mscrm.HomepageGrid.account.MainTab.Scaling._children" Sequence="120">
            <CommandUIDefinition>
              <MaxSize Id="Mscrm.HomepageGrid.account.CustomGroup.MaxSize" GroupId="Mscrm.HomepageGrid.account.CustomGroup.Group" Sequence="21" Size="LargeLarge" />
            </CommandUIDefinition>
          </CustomAction>
          <CustomAction Id="Mscrm.HomepageGrid.account.CustomGroup.Popup.CustomAction" Location="Mscrm.HomepageGrid.account.MainTab.Scaling._children" Sequence="140">
            <CommandUIDefinition>
              <Scale Id="Mscrm.HomepageGrid.account.CustomGroup.Popup.1" GroupId="Mscrm.HomepageGrid.account.CustomGroup.Group" Sequence="87" Size="Popup" />
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>


<CommandDefinitions>
          <CommandDefinition Id="Mscrm.HomepageGrid.account.CustomGroup.Button.A.Command">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <Url Address="$webresource:new_socialconn/ntier.socialconnect.engine.html" PassParams="true"></Url>
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.HomepageGrid.account.CustomGroup.Button.B.Command">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <Url Address="http://www.google.com" />
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.HomepageGrid.account.CustomGroup.Button.C.Command">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <Url Address="http://www.google.com" />
            </Actions>
          </CommandDefinition>
          <CommandDefinition Id="Mscrm.HomepageGrid.account.CustomGroup.Command">
            <EnableRules>
              <!--<EnableRule Id="Mscrm.ConvertActivity" />-->
            </EnableRules>
            <DisplayRules>
              <!--<DisplayRule Id="Mscrm.ConvertActivity" />-->
            </DisplayRules>
            <Actions />
          </CommandDefinition>
        </CommandDefinitions>

Tuesday 10 April 2012

how to connect silverlight application to dynamic crm 2011 custom ribbon button

for this:
1. in silverlight application.
select the .aspx page
ex: simplehelloTestPage.aspx (it is located in simplehello.web)
2. see the <param name="source" value="ClientBin/simplehello.xap"/> line.
In HTML page
3.give the below line
<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
instead of below line.
    <!--<script type="text/javascript" src="Silverlight.js"></script>-->
4. give the object id : <object id="SLFromJS" data="data:application/x-silverlight-2

5. now in the crm 2011 screens:
create one solution for this add webresource like:
give the name like:
new_test/ClientBin/simplehello.xap

6.create another web resource with the name:
new_test/hellohtml.html  

now  go for customization.xml for perticular entity where u created custom button.
then in the actions of particular button  give  like.
<Actions>
 <Url Address="$webresource:new_test/hellohtml.html"PassParams="true"></Url>
</Actions>
 
 then click on button you will get the silverlight application.

http://msdn.microsoft.com/en-us/library/gg309558.aspx

Friday 6 April 2012

how to read the xml file (which is getting as result) by using xml document

XmlDocument xml = new XmlDocument();
string response = _oauth.APIWebRequest("GET", "https://api.linkedin.com/v1/people/~", null,null);
//here response is in xml formate
xml.LoadXml(response);
            //XmlNodeList xnList = xml.SelectNodes("/person");
            //string firstName = "", lastName = "", headline = "";
            //foreach (XmlNode xn in xnList)
            //{
            //    firstName = xn["first-name"].InnerText;
            //    lastName = xn["last-name"].InnerText;
            //    headline = xn["headline"].InnerText;
            //    //string url = xn["url"].InnerText;
return firstName + " " + lastName + " " + headline;

multiple ways to read xml file elements:

if your xml :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<people-search>
  <people total="110" count="10" start="0">
    <person>
      <id>h2I51dNH9I</id>
      <first-name></first-name>
      <last-name>Private</last-name>
      <headline>Systems Engineer at Infosys Hyderabad</headline>
      <industry>Computer Software</industry>
      <location>
        <name>Hyderabad Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>hGBdAqDDun</id>
      <first-name>Mohan</first-name>
      <last-name>Aswapuram</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_QQ0tAHypVKsqUicjQhODAEDpZcS9BiFjXTIDAE0hb-M6ebrgo8fYxowanMDdqX6Ab5juODDW94fT</picture-url>
      <headline>PM at Infosys</headline>
      <industry>Computer Software</industry>
      <location>
        <name>Charlotte, North Carolina Area</name>
        <country>
          <code>us</code>
        </country>
      </location>
    </person>
    <person>
      <id>QQLtPL8D0W</id>
      <first-name>Deepali</first-name>
      <last-name>Singh</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_M3jGd34jZdd3NigXMQgjdC4yNWsSN82XR_dgdCo3wumgwXRkzFDabGYfsFVtcbDHZG0p6LNE5n08</picture-url>
      <headline>Technology Lead at Infosys</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Bengaluru Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>vrqwN9f2GF</id>
      <first-name>Navaneeth</first-name>
      <last-name>L.</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_YFRwQKWA52NP4ojqyiwqQ1WDLaK_Z2yqp5fqQ-MAVIkPbewN-3IbHtD0I8ryRIg4xXJvWvF7YEw0</picture-url>
      <headline>Software Engineer with experience in Business Analysis (Banking) and testing</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Coimbatore Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>zrmhI_VXKr</id>
      <first-name></first-name>
      <last-name>Private</last-name>
      <headline>Infrastrucuter support Analyst at JP Morgan</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>United Kingdom</name>
        <country>
          <code>gb</code>
        </country>
      </location>
    </person>
    <person>
      <id>JoAswhqv3b</id>
      <first-name>Anuroudh</first-name>
      <last-name>Prakash</last-name>
      <headline>Technology Lead at Infosys Technologies Ltd</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Hyderabad Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>Y-ldz8tUUp</id>
      <first-name>Manikandanprabhu</first-name>
      <last-name>Dharmaraj</last-name>
      <headline>Technology Analyst at Infosys</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Chennai Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>CBurhsmRiB</id>
      <first-name>Binu</first-name>
      <last-name>K K</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_Pk_hAcUAKBFpnqCgliLPAN2lrN8AqqigA_BxANg2flN3IKqj0CP2xqdGOVhaB1GltbTOO1_zowMB</picture-url>
      <headline>Senior Systems Engineer at Infosys Technologies Ltd</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Bengaluru Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>l0nSRwiJkp</id>
      <first-name>Shilpi</first-name>
      <last-name>Parakh</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_FiVC97OCRFovUCD1W5Rj92DTcXOJRCD15Gaj92mlHCodX6VPwLomZuVxJdY6Z5206h4yJwpeRf8P</picture-url>
      <headline>Warehouse Management Consultant - Retail clients</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>London, United Kingdom</name>
        <country>
          <code>gb</code>
        </country>
      </location>
    </person>
    <person>
      <id>fBuSS_W5-u</id>
      <first-name></first-name>
      <last-name>Private</last-name>
      <headline>Group Project Manager at Infosys Technologies Limited</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Pune Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
  </people>
</people-search>

then follow are the methods :

1.
XDocument xdoc = XDocument.Parse(e.Result);
//var persons = xdoc.Descendants("people-search");
            //var per1 = persons.Descendants("people");
            //var per2 = per1.Descendants("person");
2.
//IEnumerable<XElement> persons = xdoc.Element("people-search").Elements("people").Elements("person");
3
 var persons = xdoc.Element("people-search").Elements("people").Elements("person");

reading xml file in silverlight and bind it to datagrid

if your xml looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<people-search>
  <people total="110" count="10" start="0">
    <person>
      <id>h2I51dNH9I</id>
      <first-name></first-name>
      <last-name>Private</last-name>
      <headline>Systems Engineer at Infosys Hyderabad</headline>
      <industry>Computer Software</industry>
      <location>
        <name>Hyderabad Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>hGBdAqDDun</id>
      <first-name>Mohan</first-name>
      <last-name>Aswapuram</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_QQ0tAHypVKsqUicjQhODAEDpZcS9BiFjXTIDAE0hb-M6ebrgo8fYxowanMDdqX6Ab5juODDW94fT</picture-url>
      <headline>PM at Infosys</headline>
      <industry>Computer Software</industry>
      <location>
        <name>Charlotte, North Carolina Area</name>
        <country>
          <code>us</code>
        </country>
      </location>
    </person>
    <person>
      <id>QQLtPL8D0W</id>
      <first-name>Deepali</first-name>
      <last-name>Singh</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_M3jGd34jZdd3NigXMQgjdC4yNWsSN82XR_dgdCo3wumgwXRkzFDabGYfsFVtcbDHZG0p6LNE5n08</picture-url>
      <headline>Technology Lead at Infosys</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Bengaluru Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>vrqwN9f2GF</id>
      <first-name>Navaneeth</first-name>
      <last-name>L.</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_YFRwQKWA52NP4ojqyiwqQ1WDLaK_Z2yqp5fqQ-MAVIkPbewN-3IbHtD0I8ryRIg4xXJvWvF7YEw0</picture-url>
      <headline>Software Engineer with experience in Business Analysis (Banking) and testing</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Coimbatore Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>zrmhI_VXKr</id>
      <first-name></first-name>
      <last-name>Private</last-name>
      <headline>Infrastrucuter support Analyst at JP Morgan</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>United Kingdom</name>
        <country>
          <code>gb</code>
        </country>
      </location>
    </person>
    <person>
      <id>JoAswhqv3b</id>
      <first-name>Anuroudh</first-name>
      <last-name>Prakash</last-name>
      <headline>Technology Lead at Infosys Technologies Ltd</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Hyderabad Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>Y-ldz8tUUp</id>
      <first-name>Manikandanprabhu</first-name>
      <last-name>Dharmaraj</last-name>
      <headline>Technology Analyst at Infosys</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Chennai Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>CBurhsmRiB</id>
      <first-name>Binu</first-name>
      <last-name>K K</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_Pk_hAcUAKBFpnqCgliLPAN2lrN8AqqigA_BxANg2flN3IKqj0CP2xqdGOVhaB1GltbTOO1_zowMB</picture-url>
      <headline>Senior Systems Engineer at Infosys Technologies Ltd</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Bengaluru Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
    <person>
      <id>l0nSRwiJkp</id>
      <first-name>Shilpi</first-name>
      <last-name>Parakh</last-name>
      <picture-url>http://media.linkedin.com/mpr/mprx/0_FiVC97OCRFovUCD1W5Rj92DTcXOJRCD15Gaj92mlHCodX6VPwLomZuVxJdY6Z5206h4yJwpeRf8P</picture-url>
      <headline>Warehouse Management Consultant - Retail clients</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>London, United Kingdom</name>
        <country>
          <code>gb</code>
        </country>
      </location>
    </person>
    <person>
      <id>fBuSS_W5-u</id>
      <first-name></first-name>
      <last-name>Private</last-name>
      <headline>Group Project Manager at Infosys Technologies Limited</headline>
      <industry>Information Technology and Services</industry>
      <location>
        <name>Pune Area, India</name>
        <country>
          <code>in</code>
        </country>
      </location>
    </person>
  </people>
</people-search>

then first create a class for this :
public class Person
        {
            public string id { get; set; }
            public string firstname { get; set; }
            public string lastname { get; set; }
            public string headline { get; set; }
            public string industry { get; set; }
            public string location { get; set; }
            public string country { get; set; }
            public string url { get; set; }

            //public Uri sitestandardprofilerequest { get; set; }         
       
    }

then in the :
private void proxy_SearchForContactCompleted(object sender,SearchForContactCompletedEventArgs e)
        {
            XDocument xdoc = XDocument.Parse(e.Result);
            //ObservableCollection<Person> _PersonList = new ObservableCollection<Person>();
            List<Person> _PersonList = new List<Person>();
          
            string[] a = new string[] { };
            int i = 0;
            //var persons = xdoc.Descendants("people-search");//.Descendants("people-search")//.Elements("people-search")
            //var per1 = persons.Descendants("people");
            //var per2 = per1.Descendants("person");
          
            //IEnumerable<XElement> persons = xdoc.Element("people-search").Elements("people").Elements("person");
            var persons = xdoc.Element("people-search").Elements("people").Elements("person");
            foreach (var _persons in persons)
           
            {
                Person obj = new Person() { };

                //obj.id = _persons.Element("people").Element("person").Element("id").Value.ToString();
                obj.id = _persons.Element("id").Value.ToString();
                obj.firstname = _persons.Element("first-name").Value.ToString();
                obj.lastname = _persons.Element("last-name").Value.ToString();
                obj.headline = _persons.Element("headline").Value.ToString();
                obj.industry = _persons.Element("industry").Value.ToString();
                obj.location = _persons.Element("location").Element("name").Value.ToString();

                //obj.firstname = _persons.Element("people").Element("person").Element("first-name").Value.ToString();//_persons.Element("first-name").Value.ToString();
                //obj.lastname = _persons.Element("people").Element("person").Element("last-name").Value.ToString();//_persons.Element("last-name").Value.ToString();
                    //obj.headline = _persons.Element("people").Element("person").Element("headline").Value.ToString();//_persons.Element("headline").Value.ToString();
                    //obj.url = _persons.Element("site-standard-profile-request").Element("url").Value.ToString();
                    //obj.industry = _persons.Element("people").Element("person").Element("industry").Value.ToString();//_persons.Element("industry").Value.ToString();
                    //obj.location = _persons.Element("people").Element("person").Element("first-name").Value.ToString();//_persons.Element("location").Element("name").Value.ToString();
                    // obj.country = _persons.Element("people").Element("person").Element("first-name").Value.ToString();//_persons.Element("location").Element("country").Element("code").Value.ToString();
                    _PersonList.Add(obj);
                    //i++;
                    //_persons++;
               

            }
           

            dataGrid1.ItemsSource = _PersonList.ToArray();

        }

Thursday 5 April 2012

bind a xml result into datagrid in silverlight

first check : AutoGenerateColumns="True" in datagrid.

if you want to do in web services or asp.net places:

XmlDocument xml = new XmlDocument();
         xml.LoadXml(response);
         XmlNodeList xnList = xml.SelectNodes("/person");

         //int[] ids = new int[10];
       
         //string[] str = new string[10];
         //int i = 0;
         string firstName="", lastName="", headline="";
         foreach (XmlNode xn in xnList)
         {
              firstName = xn["first-name"].InnerText;
              lastName = xn["last-name"].InnerText;
              headline = xn["headline"].InnerText;
             //string url = xn["url"].InnerText;
             //Console.WriteLine("Name: {0} {1}", firstName, lastName);
         }

XmlDocument will work.

if you want to do in silverlight scree:
first check the result which fields are coming in result.

if you are getting result like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
  <first-name>Damu</first-name>
  <last-name>P</last-name>
  <headline>--</headline>
  <site-standard-profile-request>
    <url>http://www.linkedin.com/profile?viewProfile=&amp;key=123089296&amp;authToken=NpQD&amp;authType=name&amp;trk=api*a170167*s178416*</url>
  </site-standard-profile-request>
</person>

then we need to print this xml in datagrid:

for this first create on class function in silverlight screen:

   public class Person
        {
          
            public string firstname { get; set; }
            public string lastname { get; set; }
            public string headline { get; set; }
            public string url { get; set; }
            //public Uri sitestandardprofilerequest { get; set; }        
       
    }

then :

XDocument xdoc = XDocument.Parse(e.Result);
            List<Person> _PersonList = new List<Person>(10);
            Person obj = new Person();
            string[] a = new string[] { };
            int i=0;
            var persons = from d in xdoc.Elements("person")
                        select d;
          
            foreach (var _persons in persons)
            {
              
                obj.firstname=_persons.Element("first-name").Value.ToString();
                obj.lastname = _persons.Element("last-name").Value.ToString();
                obj.headline = _persons.Element("headline").Value.ToString();
                obj.url = _persons.Element("site-standard-profile-request").Element("url").Value.ToString();
                _PersonList.Add(obj);
                i++;
              
              
            }

            dataGrid1.ItemsSource = _PersonList;

you will get the result in grid view.

Tuesday 3 April 2012

saving the access token in dynamic crm 2011

public string GetAccessToken()
        {

            _oauth.Token = Application["auth_token"].ToString();
            _oauth.TokenSecret = Application["auth_tokensecret"].ToString();
            _oauth.Verifier = Application["auth_verifier"].ToString();


            _oauth.AccessTokenGet(Application["auth_token"].ToString());

            //string oauth_access = Application["auth_token"].ToString();
            Application["oauth_access"] = _oauth.Token;//Application["oauth_token"].ToString();
            //string oauth_access_secret = Application["auth_tokensecret"].ToString(); oauth_token_secret
            Application["oauth_access_secret"] = _oauth.TokenSecret; //Application["oauth_token_secret"].ToString();

            ClientCredentials Credentials = new ClientCredentials();
            Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            //This URL needs to be updated to match the servername and Organization for the environment.

            Uri OrganizationUri = new Uri("http://<crmserver>/<organization name>/XRMServices/2011/Organization.svc");
            Uri HomeRealmUri = null;
            //OrganizationServiceProxy serviceProxy;   

            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
            {
                IOrganizationService service = (IOrganizationService)serviceProxy;
                //Instantiate the contact object and populate the attributes.
                Entity new_cooldrink = new Entity("new_cooldrink");
                //Entity Contact = new Entity("contact");
                new_cooldrink["new_name"] = Application["oauth_access"].ToString();//TextBox1.Text.ToString();//txtFirstName.Text.ToString();
                //contact["lastname"] = txtLastName.Text.ToString();
                //contact["emailaddress1"] = txtEmailAddress.Text.ToString();
                //contact["telephone1"] = txtPhoneNumber.Text.ToString();
                Guid newnew_cooldrinkid = service.Create(new_cooldrink);
                //This code will clear the textboxes after the contact is created.
                //TextBox1.Text = "";
            }

            return _oauth.Verifier;

        }

create a record in dynamic crm 2011 frow web application

first Create a web application.from Framwork 4.0.

In ASPX we can give one label, one textbox and one button

My example:

<p>
        this is the trail to create a record in &quot;new_cooldrink&quot; entity at dynamic crm
        2011.</p>
    <p>
        <asp:Label ID="Label1" runat="server" Text="name"></asp:Label>
&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </p>
    <p>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="save" />
    </p>

code in c#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using System.Net;
using Microsoft.Xrm.Sdk;
using System.Runtime.Serialization;
using System.Data;
using System.Data.Entity;

namespace connectcrm2011
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            ClientCredentials Credentials = new ClientCredentials();
            Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            //This URL needs to be updated to match the servername and Organization for the environment.

            Uri OrganizationUri = new Uri("http://<servername>/<organization name>/XRMServices/2011/Organization.svc");
            Uri HomeRealmUri = null;
            //OrganizationServiceProxy serviceProxy;   

            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
            {
                IOrganizationService service = (IOrganizationService)serviceProxy;
                //Instantiate the contact object and populate the attributes.
                Entity contact = new Entity("contact");
                //Entity new_cooldrink = new Entity("new_cooldrink");
                contact["lastname"] = TextBox1.Text.ToString();//txtFirstName.Text.ToString();
                 //new_cooldrink["new_name"] = Application["oauth_access"].ToString();
                //contact["lastname"] = txtLastName.Text.ToString();
                //contact["emailaddress1"] = txtEmailAddress.Text.ToString();
                //contact["telephone1"] = txtPhoneNumber.Text.ToString();
                Guid newContactId = service.Create(contact);
                 //for account entity
                //Guid newaccountId = service.Create(account);
                //Guid newnew_cooldrinkid = service.Create(new_cooldrink);
                //This code will clear the textboxes after the contact is created.
                TextBox1.Text = "";
                  }
        }
    }
}

Note : must add the reference
1. System.Runtime.Serialization
2.System.Data.Entity
  in reference area.

may be cause for error:

Thread: Error: Reference required to assembly 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral,..

then in webconfig:  

<compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation> 

ref: http://blogs.msdn.com/b/crminthefield/archive/2011/05/18/how-to-create-a-simple-webpage-leveraging-the-crm-2011-iorganizationservice-web-service.aspx 

for this we need to add the reference :   

System.Runtime.Serialization 

in reference area.