Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

How to Insert top 10 record using API

$
0
0

I am using a console application in which I have  deserialize JSON object into c# class now I want to insert the top 10 records using the console application

using BGImporter.Models;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Crm.Sdk.Messages;
using System.ServiceModel.Description;
using System.Threading.Tasks;
using System.Net.Http;

namespace BGImporter
{
class Program
{

static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string URL = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
RestClient client = new RestClient(URL);

client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddParameter("text/plain", "", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

IOrganizationService organizationService = null;
try
{
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "XXXXXXXXX";
clientCredentials.UserName.Password = "XXXXXXXXX";
// For Dynamics 365 Customer Engagement V9.X, set Security Protocol as TLS12
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Get the URL from CRM, Navigate to Settings -> Customizations -> Developer Resources
// Copy and Paste Organization Service Endpoint Address URL
organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri("">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
null, clientCredentials, null);
if (organizationService != null)
{
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
if (userid != Guid.Empty)
{
Entity objClient = new Entity("contact");
objClient["firstname"] = "tEishantST1";//"] = "";//single line of text
objClient["lastname"] = "TEST";//single line of text
OptionSetValue objovalue = new OptionSetValue(1);
objClient["new_sesso"] = objovalue;//option set
objClient["new_luogodinascita"] = "tEST";//single line of text
var date = Convert.ToDateTime("2021/03/03");
objClient["new_datadinascita"] = date;//date time
objClient["new_codicefiscale"] = "TEst";//single line of text
var id=organizationService.Create(objClient);
Console.WriteLine("Connection Successful!...");
}
}
else
{
Console.WriteLine("Failed to Established Connection!!!");
}
}
catch (Exception ex)
{
Console.WriteLine("Exception caught");
}
Console.ReadKey();
}

public static void ConsulentiData()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var consulenti = new RestClient("XXXXXXXXXXXXXXXXX");

// Method which we want to call
var request = new RestRequest("Consulent");
var response = consulenti.Execute(request);
//if request status is ok then we will handle the request
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
string rawResponse = response.Content;
var result = JsonConvert.DeserializeObject<List<Consulent>>(response.Content);


}
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var clienti = new RestClient("XXXXXXXXXXXXXXX");
// Method which we want to call
var request1 = new RestRequest("Client");
var response1 = clienti.Execute(request1);
//if request status is ok then we will handle the request
if (response1.StatusCode == System.Net.HttpStatusCode.OK)
{
string rawResponse1 = response1.Content;
var result1 = JsonConvert.DeserializeObject<List<Client>>(response1.Content);

foreach()


}
}



}


}


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>