Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 Release Wave 2Discover the latest updates and new features to Dynamics 365 planned through March 2021.
Release overview guides and videos Release Plan | Preview 2020 Release Wave 2 TimelineWatch the 2020 Release Wave 2 virtual launch event
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
Have you ever needed to connect to the Web services of one NAV instance from another one? If so, I bet that the approach was something like this: you created a .NET class where you defined a Web or Service reference to the target instance, and then you consumed that .NET class using .NET Framework interoperability. It was kind of clumsy, inflexible, but it worked.
How cool would it be if you could do something like this:
WITH WebService DO BEGIN CONNECT(‘http://localhost:7047/DynamicsNAV70/WS/CRONUS%20International%20Ltd/Page/Customer’);
INIT; SETVALUE(‘Name’,'Test Customer’); SETVALUE(‘Blocked’,Cust.Blocked::Ship); SETVALUE(‘Credit_Limit_LCY’,10000); CREATE;
MESSAGE(‘I just created Customer No. %1 in another NAV instance.’,GETVALUE(‘No’)); END;
As a matter of fact, you can write something like that. You can write exactly that. And it compiles, runs, and accomplishes exactly what you expect it to do. The most beautiful thing, you don’t need to write a single line of code in Visual Studio, or deploy any external dependencies – it uses pure C/AL, and works equally well in NAV 2009 and NAV 2013.
The only thing you need is a simple codeunit that you can download from Mibuso. (The upload is pending approval at the time of posting of this blog, and I’ll update it as soon as the download becomes available.)
I wrote that codeunit as a part of the demo I presented last Wednesday at Mibuso NAV TechDays 2012 in Antwerp, and as promised – I am making the code available for you to use.
This simple codeunit does no magic, it simply harnesses the power of the features built into the .NET Framework. It builds the proxy class and compiles it on the fly, and then uses reflection to instantiate objects, set properties, and call methods to allow you to interact with any NAV page web service.
Before you can consume a NAV page Web service from C/AL you do not need to know anything about the service, except for its URL. If it’s a page web service, you can use it to read, create, update, and delete data in another NAV instance, simply using C/AL.
At this stage, it supports the following page web service functions:
Right now, I am providing no documentation for it, but I believe it should not be difficult to figure out what it can do by following these couple of examples.
That’s the example above. Just declare a variable named WebService of type Codeunit 50113, and you are good to go.
WITH WebService DO BEGIN CONNECT(‘http://localhost:7047/DynamicsNAV70/WS/CRONUS%20International%20Ltd/Page/Customer’); SETFILTER(‘Balance_LCY’,'>0′); SETFILTER(‘Name’,'A*’); IF READMULTIPLE THEN REPEAT MESSAGE(‘Customer %1 %2 has balance of %3′,GETVALUE(‘No’),GETVALUE(‘Name’),GETVALUE(‘Balance_LCY’)); UNTIL NEXT = 0; END; EXIT;
WITH WebService DO BEGIN INIT; SETVALUE(‘No’,’1000’); READ; SETVALUE(‘Description’,’Bicycle 2’); UPDATE; END;
WITH WebService DO BEGIN CONNECT(‘http://localhost:7047/DynamicsNAV70/WS/CRONUS%20International%20Ltd/Page/PurchOrder’); INIT; SETVALUE(‘Buy_from_Vendor_No’,Rec."Sell-to Customer No."); SalesLine.SETRANGE("Document Type",Rec."Document Type"); SalesLine.SETRANGE("Document No.",Rec."No."); IF SalesLine.FINDSET THEN REPEAT NEWLINE; SETLINEVALUE(‘Type’,FORMAT(SalesLine.Type)); SETLINEVALUE(‘No’,FORMAT(SalesLine."No.")); SETLINEVALUE(‘Quantity’,SalesLine.Quantity); UNTIL SalesLine.NEXT = 0; CREATE; MESSAGE(‘Purchase Order No. %1 is created in the vendor”s system.’,GETVALUE(‘No’)); END;
I’ll be updating the functionality of this codeunit and uploading a more comprehensive version, as I find time to do this.
This post is a series of posts where I’ll present most of the stuff I talked about at NAV TechDays 2012, and expand those topics into the areas that I either had to leave out due to time constraints, or that I thought were not as interesting as those that I chose to put into the presentation.
Please, let me know how you like this small gadget.
Business Applications communities