Synch data from BC(Item Unit of Measure Table) to CRM(Customized Table same structure like BC table)

Pradeep1611
Member Posts: 8
Hi Experts,
I need to synch data from Business Central ("Item Unit of Measure" Table) to CRM (New Customized Table same structure like BC table).
I used CDS setup for this but not able to synch this because of this table is not showing in Table Mapping in CDS.
So, I go with AL Code level but NAV integration concept is not working in Business Central OnCloud because of DotNet variable not supported in Business Central AL code.
So, I need your help/suggestion how I can achieve this, I have CRM webservice/api having data form in JSON, below are API url from CRM...
1) https://[ORG URI].api.crm4.dynamics.com/XRMServices/2011/Organization.svc?wsdl (this have all webservices inside the CRM)
2) https://[ORG URI].crm4.dynamics.com/api/data/v9.1/beg_itemunitofmeasures (this is a particular table access url from CRM called as Item Unit of Measure in CRM this is customized table and having same fields and structure same like BC table of Item Unit Of Measure)
I need to understand how to make above API Authentication in Business Central in AL code and how to synch data from BC to CRM using these API.
Thanks in Advance.
I need to synch data from Business Central ("Item Unit of Measure" Table) to CRM (New Customized Table same structure like BC table).
I used CDS setup for this but not able to synch this because of this table is not showing in Table Mapping in CDS.
So, I go with AL Code level but NAV integration concept is not working in Business Central OnCloud because of DotNet variable not supported in Business Central AL code.
So, I need your help/suggestion how I can achieve this, I have CRM webservice/api having data form in JSON, below are API url from CRM...
1) https://[ORG URI].api.crm4.dynamics.com/XRMServices/2011/Organization.svc?wsdl (this have all webservices inside the CRM)
2) https://[ORG URI].crm4.dynamics.com/api/data/v9.1/beg_itemunitofmeasures (this is a particular table access url from CRM called as Item Unit of Measure in CRM this is customized table and having same fields and structure same like BC table of Item Unit Of Measure)
I need to understand how to make above API Authentication in Business Central in AL code and how to synch data from BC to CRM using these API.
Thanks in Advance.
0
Answers
-
Hi,
dotnets are not supported anymore but in AL you can connect to WS.
You can use AL "functions", use for example "waldo´s pack":
https://www.waldo.be/2019/12/05/waldo-restapp/
Also you can use this piece I use.
I just the case 0: but it is handy to have the other methods. You just need request url formed and username/pwd
CallService('myproject', vWSURL, RequestType, payload, T50049.UserName, T50049.Password);procedure CallService(ProjectName: Text; RequestUrl: Text; RequestType: Integer; payload: Text; Username: Text; Password: Text): Text var Client: HttpClient; RequestHeaders: HttpHeaders; RequestContent: HttpContent; ResponseMessage: HttpResponseMessage; RequestMessage: HttpRequestMessage; ResponseText: Text; contentHeaders: HttpHeaders; begin RequestHeaders := Client.DefaultRequestHeaders(); RequestHeaders.Add('Authorization', CreateBasicAuthHeader(Username, Password)); case RequestType of 0: Client.Get(RequestURL, ResponseMessage); 1: begin RequestContent.WriteFrom(payload); RequestContent.GetHeaders(contentHeaders); contentHeaders.Clear(); contentHeaders.Add('Content-Type', 'application/json'); RequestMessage.Content := RequestContent; RequestMessage.SetRequestUri(RequestURL); // RequestMessage.Method := 'PATCH'; RequestMessage.Method := 'PUT'; client.Put(RequestURL, RequestContent, ResponseMessage); end; 2: begin RequestContent.WriteFrom(payload); RequestContent.GetHeaders(contentHeaders); contentHeaders.Clear(); contentHeaders.Add('Content-Type', 'application/json'); Client.Post(RequestURL, RequestContent, ResponseMessage); end; 3: Client.Delete(RequestURL, ResponseMessage); end; ResponseMessage.Content().ReadAs(ResponseText); if ResponseMessage.HttpStatusCode <> 200 then begin if StrPos(ResponseText, '"message"') <> 0 then ResponseText := CopyStr(ResponseText, StrPos(ResponseText, '"message"') + 10, StrLen(ResponseText)); Error(strsubstno(Text50004, ResponseMessage.HttpStatusCode, ResponseText, payload)); end else exit(ResponseText); end; procedure CreateBasicAuthHeader(UserName: Text; Password: Text): Text var TempBlob: Record TempBlob; begin TempBlob.WriteAsText(StrSubstNo('%1:%2', UserName, Password), TextEncoding::UTF8); exit(StrSubstNo('Basic %1', TempBlob.ToBase64String())); end;
And this is an example to write JSON, (I cleared a bit the names because points to real work). To read it I haven´t used but you will find it: vJsonObject.ReadFrom()vJsonObject: JsonObject; vJsonValue: JsonValue; vJsonArray: JsonArray; vJsonObject.Add('path', '/app:company_home/cm:System/'); vJsonObject.Add('type', 'linkedValue'); vJsonObject.Add('lkvValue', Format(vFieldRef.Value)); vJsonObject.Add('erpCode', Format(vFieldRef.Value)); vJsonValue.ReadFrom('1'); vJsonObject.Add('depthLevel', vJsonValue.AsInteger()); vJsonObject.WriteTo(vpayload);
Then, if you want to happen every time they change something in 5404 table, just create an event subscriber.
I hope all this is useful to whatever you are trying to do (send/receive data from nav).
1 -
Thank you @txeriff0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions