Skip to content

ArcherPoint Dynamics NAV Developer Digest - vol 208ArcherPoint's Developer Digest Weekly Blog

The NAV community, including the ArcherPoint technical staff, is made up of developers, project managers, and consultants who are constantly communicating, with the common goal of  sharing helpful information with one another to help customers be more successful.

As they run into issues and questions, find the answers, and make new discoveries, they post them on blogs, forums, social media...so everyone can benefit. We in Marketing watch these interactions and never cease to be amazed by the creativity, dedication, and brainpower we’re so fortunate to have in this community—so we thought, wouldn’t it be great to share this great information with everyone who might not have the time to check out the multitude of resources out there? So, the ArcherPoint Microsoft Dynamics NAV Developer Digest was born. Each week, we present a collection of thoughts and findings from NAV experts and devotees around the world. We hope these insights will benefit you, too.

Looking for a JSON Object Type in Dynamics NAV? You’re Not the Only One

Kyle shares, “I wish NAV had a JSONPort object type.”

Matt T asks, “What version are you working with? Check out CU1234 - JSON Text Reader/Writer if it's there. If not there's a good chance it could be backported as long as you're on a semi-recent version.”

Kyle responds, “Thanks for the suggestion - I will try backporting from NAV 2018 to NAV 2017.”

Saurav chimes in, “I have it used for a project in NAV 2017. I didn't bring the codeunit, but I have coded with it in NAV 2017 and its still running. Let me know if I can help.”

Kyle updates, “I backported table 1236 JSON Buffer from NAV 2018 to NAV 2017 and it works like magic. I have an HTTPGET response that is JSON in a BLOB, and I can feed it into that table and parse out the pieces with the function ReadFromText. Dynamics NAV 2018 also has some other codeunits that can do things like translate JSON to XML, but I don't know that I care much about XML anymore...”

Saurav responds, “The part that converts JSON to XML is what I used. It puts that data into an XMLBuffer table that then can be read into NAV based on Tags / Parent Node that you want to use.”

Sample Code to Make a REST Call to Bing Maps API

Kyle then shares, “This is sample code that makes a REST call to Bing Maps API and harvests the JSON response to get a road-route distance between two GPS points.

It will work in NAV 2018 or in NAV 2017 if you back-port table 1236 JSON Buffer.

Template URL for Bing Maps API (authorization required)

%1 origin lat

%2 origin long

%3 destination lat

%4 destination lomg

%5 developer key (from the Bing Maps Portal)

travelMode is self-documenting but startTime is weird. It is a special format that defaults to Today because no date is specified, but at 2 o’clock in the morning Eastern Time (UTC minus five hours), Bing uses this for route decisions based on the time of day and traffic.”

Kyle’s Developer Tip of the Day

Progress bars are useful to give the user feedback during long-running processes like XML exports. 
 
Text001: #1######## of #2#########\@@@@@@@@@@@@@@@@@@@@@@@3@ 
Integer TotalCount, Counter 
Dialog Window 
 
OnBeginWhatever 
TotalCount := Record.COUNT; 
Window.OPEN(Text001); 
Window.UPDATE(2, TotalCount); 
 
OnExportWhatever 
Counter += 1; 
Window.UPDATE(1, Counter); 
Window.UPDATE(3, ROUND(Counter / TotalCount * 10000, 1)); 
 
OnAfterWhatever 
Window.CLOSE; 

Michael adds, “Please don't forget IF GUIALLOWED THEN. *Always* prepend to dialog windows, CONFIRMs, and MESSAGEs to facilitate processing in Application Server (i.e. Job Queue).”

Bill W comments, “I'm not sure this is the case anymore on newer NAV versions. CU 80 still has Window.UPDATE code and you can setup background posting out of the box.”

XML Port Generator

Kyle gives a shout out to ArcherPoint’s Bill Warnke,“I needed an automatic XMLPort generator, and a duckduckgo search took me to a GitHub solution posted by eknraw, which is Warnke spelled backwards.” 
 
Matt exclaims, “The Batman has been unmasked! Secret identity exposed!”

Bill replies, “Nice! I did just update it with a couple of bugfixes that I've been meaning to push up to GitHub. This was a totally re-written version of something created to migrate a very large database. 

Also, good blog post idea, ’Code Search versus Curated Solution Repos’.  
 
And my name IS right in the profile page.”

If you are interested in NAV development, be sure to see our collection of NAV Development Blogs.

Read the "How To" blogs from ArcherPoint for practical advice on using Microsoft Dynamics NAV, and contact ArcherPoint if you need assistance with Dynamics NAV.

Blog Tags: 
Read ArcherPoint's Blog Follow us on Twitter Follow us on Facebook Follow us on LinkedIn Link to our RSS feed Join us on Google+ Watch us on YouTube
Get Help Now