Posted in CRM

Console Application for updating the records

Console Application For Updating the Lead Records :-

Without opening the records in CRM we can update the leads data through console application. For console application we are going with CRMSERVICECLIENT

 

Namespaces:-
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector; // for connecting the crm service client;
using System.Configuration;  //getting the credentials from app.config file;
using Microsoft.Xrm.Sdk.Query;  // for fetchexpression

App.config file;-
<connectionStrings>
 <add name="CRM" connectionString="AuthType=Office365;Url=https://*****.crm8.dynamics.com; Username=admin@***.onmicrosoft.com; Password=***" />
 </connectionStrings>


Code-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Tooling.Connector;
using System.Configuration;
using Microsoft.Xrm.Sdk.Query;

namespace CRM_Console_Application
{
 class Program
 {
 static void Main(string[] args)
 {
 CrmServiceClient client = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString);
 IOrganizationService service = client.OrganizationServiceProxy;
 string fetchxml = string.Format(Resource1.String1);
 EntityCollection leads = service.RetrieveMultiple(new FetchExpression(fetchxml));
 
 foreach (var lead in leads.Entities)
 {
 //Entity leadentity = new Entity("lead");
 lead.Attributes["emailaddress1"] ="balabramha@gmail.com";
 lead.Attributes["mobilephone"] = "9059289083";
 service.Update(lead);
 }
 }
 }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s