У меня есть следующие данные JSON, хранящиеся во внешней базе данных:
{
"id": "emulator:conversation4acee870-4bf7-11e9-849f-abbeb92fb354|livechat",
"botId": "05682e70-4410-11e9-bd6d-d3b4ec617e06",
"channelId": "emulator",
"conversationId": "4acee870-4bf7-11e9-849f-abbeb92fb354|livechat",
"userId": "72aee04c-8ce5-4c1e-abfe-32680a5f2404",
"data": {
"FirstName": "sam",
"Surname": "smith"
},
"etag":"2355667676",
"attachement":"222445666"
}
Я хотел бы получить значения firstname
и поместить их в динамический новый контактный объект.
В данный момент я создал консольное приложение и подключился к своей внешней базе данных и динамику 365. Подключение из консольного приложения к динамике работает.Я могу запросить базу данных и получить значения запроса.Однако я не знаю, как вставить данные JSON в динамику.
class Program
{
public static IOrganizationService axoService;
public static IOrganizationService service;
private Guid _accountId;
public Guid _contactId;
//connect to cosmos db
private const string EndpointUrl = "https://botstore.documents.azure.com:###/";
private const string PrimaryKey = "Z###########################=";
private DocumentClient client;
static void Main(string[] args)
{
Task.Run(async () =>
{
var endpoint = EndpointUrl;
var masterKey = PrimaryKey;
using (var client = new DocumentClient(new Uri(endpoint), masterKey))
{
Console.WriteLine(">>>> Querying Document <<<<<<");
//returns all
var response = client.CreateDocumentQuery(UriFactory.CreateDocumentCollectionUri("botdb","botcollection"),"select * from c").ToList();
//returns first one
var g = response.First();
Console.WriteLine($"id:{g.id}");
//return botid contains convo
var p = response.Where(op => op.id.Contains("conv")).ToList().First();
Console.WriteLine($"id2:{p.id}");
Console.WriteLine($"id2:{p.botId}");
Console.WriteLine($"id2:{p.data.FirstName}");
Console.WriteLine("Query done");
//After query delete conversation? maybe after it is added to dynamics, then delete in another function
var connectionString = @"AuthType = Office365; Url = https://#####.crm11.dynamics.com/;Username=s######@dynamics.co.uk;Password=########";
CrmServiceClient conn = new CrmServiceClient(connectionString);
axoService = conn.OrganizationServiceProxy;
IOrganizationService _orgService;
orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
RetrieveVersionResponse versionResponse =(RetrieveVersionResponse)_orgService.Execute(versionRequest);
Console.WriteLine("Microsoft Dynamics CRM version {0}.",versionResponse.Version);
var pop = p.data.FirstName;//gets the value from json
data//sam
Entity cont = new Entity("contact");
cont["firstname"] = pop;//error:Type **'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself.**- this is not WCF though so don't have service references
cont["lastname"] = "Simmmmmmspsson";
axoService.Create(cont);
Console.WriteLine("new contact added");
Console.ReadLine();
Как вставить данные JSON в поле FirstName в контактной сущности в Microsoft Dynamics?