Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home CSharp Retrieve Account With Microsoft Dynamics CRM Web Services By C#

Retrieve Account With Microsoft Dynamics CRM Web Services By C#

From last tutorial, we created an Account with these information: name, accountnumber, address1_postalcode, address1_city, emailaddress1, address1_telephone1, description, telephone1. And the GUID for the Account is: 0b00108f-8757-e011-a444-e61f13c072b3.

In this tutorial, I will show how to retrieve an Account entity by using CrmService.Retrieve method of Microsoft Dynamics CRM Web Services.

If you lost our last tutorial, please read this post first: http://4rapiddev.com/csharp/create-account-with-microsoft-dynamics-crm-web-services-by-c/

The C# source code below will:

  • Create a CRM Service instance
  • Create a column set object and set the properties of the column set
  • Retrieve the Account Entity by calling the Retrieve method
  • Display the account information

Here you go – file retrieve_account.aspx in the source code attachment:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using CRM;
 
public partial class retrieve_account : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string organization = "your-organization";
        string server = "your-server:your-port-number-if-any";
        string domain = "your-domain";
        string username = "your-username";
        string password = "your-password";
 
        //Create CRM Service instance
        CrmService service = crm_demo.IFDConnectionDemo(organization, server, domain, username, password);
 
        //Create the column set object that indicates the properties to be retrieved.
        //And set the properties of the column set.
        ColumnSet cset = new ColumnSet(new string[] { "name", "accountnumber", "address1_postalcode", "address1_city", "emailaddress1", "address1_telephone1", "description", "telephone1" });
 
        // accountGuid is the GUID of the record being retrieved.
        Guid accountGuid = new Guid("0b00108f-8757-e011-a444-e61f13c072b3");
 
        //Retrieve the Account
        account account = (account)service.Retrieve(EntityName.account.ToString(), accountGuid, cset);
 
        //Display the Account Detail
        if (account.name != null)
            Response.Write("name: " + account.name.ToString() + "<br>");
 
        if (account.accountnumber != null)
            Response.Write("accountnumber: " + account.accountnumber.ToString() + "<br>");
 
        if (account.address1_postalcode != null)
            Response.Write("address1_postalcode: " + account.address1_postalcode.ToString() + "<br>");
 
        if (account.address1_city != null)
            Response.Write("address1_city: " + account.address1_city.ToString() + "<br>");
 
        if (account.emailaddress1 != null)
            Response.Write("emailaddress1: " + account.emailaddress1.ToString() + "<br>");
 
        if (account.address1_telephone1 != null)
            Response.Write("address1_telephone1: " + account.address1_telephone1.ToString() + "<br>");
 
        if (account.description != null)
            Response.Write("description: " + account.description.ToString() + "<br>");
 
        if (account.telephone1 != null)
            Response.Write("telephone1: " + account.telephone1.ToString() + "<br>");
    }
}

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.Crm.Sdk; using Microsoft.Crm.Sdk.Query; using Microsoft.Crm.SdkTypeProxy; using CRM; public partial class retrieve_account : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string organization = "your-organization"; string server = "your-server:your-port-number-if-any"; string domain = "your-domain"; string username = "your-username"; string password = "your-password"; //Create CRM Service instance CrmService service = crm_demo.IFDConnectionDemo(organization, server, domain, username, password); //Create the column set object that indicates the properties to be retrieved. //And set the properties of the column set. ColumnSet cset = new ColumnSet(new string[] { "name", "accountnumber", "address1_postalcode", "address1_city", "emailaddress1", "address1_telephone1", "description", "telephone1" }); // accountGuid is the GUID of the record being retrieved. Guid accountGuid = new Guid("0b00108f-8757-e011-a444-e61f13c072b3"); //Retrieve the Account account account = (account)service.Retrieve(EntityName.account.ToString(), accountGuid, cset); //Display the Account Detail if (account.name != null) Response.Write("name: " + account.name.ToString() + "<br>"); if (account.accountnumber != null) Response.Write("accountnumber: " + account.accountnumber.ToString() + "<br>"); if (account.address1_postalcode != null) Response.Write("address1_postalcode: " + account.address1_postalcode.ToString() + "<br>"); if (account.address1_city != null) Response.Write("address1_city: " + account.address1_city.ToString() + "<br>"); if (account.emailaddress1 != null) Response.Write("emailaddress1: " + account.emailaddress1.ToString() + "<br>"); if (account.address1_telephone1 != null) Response.Write("address1_telephone1: " + account.address1_telephone1.ToString() + "<br>"); if (account.description != null) Response.Write("description: " + account.description.ToString() + "<br>"); if (account.telephone1 != null) Response.Write("telephone1: " + account.telephone1.ToString() + "<br>"); } }

Microsoft Dynamics CRM Web Services Retrieve Account Entity

Microsoft Dynamics CRM Web Services Retrieve Account Entity

Note:

  • You can use AllColumns to retrieve all informations instead of listing attributes one by one.
  • When display/use these attributes, you should check to if it is not null, ex: if (account.name != null)

Download the source code above

Mar 27, 2011Hoan Huynh
View Word Wrap and Line Numbers in Microsoft Visual Web Developer 2010 ExpressMSSQL Split String Function
You Might Also Like:
  • Create Account With Microsoft Dynamics CRM Web Services By C#
  • Dymanic Crm Error 401 Unauthorized When Create Or Retrieve Account And Contact
  • Create And Assign Account To A User In Microsoft Dynamic CRM With C#
  • Property or indexer ‘Microsoft.Crm.Sdk.Query.ColumnSet.Attributes’ cannot be assigned to – it is read only
  • Property or indexer ‘Microsoft.Crm.Sdk.Query.FilterExpression.Conditions’ cannot be assigned to – it is read only
  • Change or reset MySQL Root Account Password
  • Create CrmService with Domain, Username And Password
  • Get Familiar With Microsoft Dynamics CRM Development Customization Levels
  • ASP.NET C# Export Data To CSV And Prompt Download
  • Replace String With NText Or Text Data Type In MS SQL Server
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

10 years ago CSharpAllColumns, ColumnSet, Crm, CrmService, CrmService.Retrieve, Microsoft, Microsoft Dynamics CRM, SDK627
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,195 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,069 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,845 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,321 views
C# Read Json From URL And Parse/Deserialize Json
9,815 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Free Online Photo Editor
  • Easy Tips For Writing An Essay
  • What Can I Expect From An Academic Essay Service?

  • Can Be Essay Service Companies Good For You?

  • Tips To Choosing The Ideal Essay Writers
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (112)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development