Search the site

Modifying NAV calls

Terminology

Action Word                     - When communicating with NAV from TradePoint, an action word is passed along to identify which action to perform.

NAV                                   - Dynamics NAV, previously known as Navision

NAS                                   - Navision Application Server - a service which in TradePoint's case polls a specified Message Queue for messages to handle.

Scriptlet                             - A ScriptServer concept. A scriptlet is an object with methods, all defined in script code inside ScriptServer. Scriptlets are modified using the Scriptlet Manager.

TradePoint MQ Form      - An alternate solution to using the NAS. Should only be used for debugging and testing purposes.

Calls to NAV

When calling NAV to either perform an action or to retrieve a value, TradePoint does this through a scriplet method: TradePoint.InvokeTP(). This method has a couple of parameters which are explained below:

 

TradePoint.InvokeTP(actiontype, convertToRecordSet, paramNames, paramValues, customerNo, cacheMode, cacheMinutes)

 

  • actionWord - An unique word, specified in NAV in a TradePoint code unit. It identifies the action to be performed. You can add more action words yourself and you can also reuse the existing ones
  • convertToRecordSet - A Boolean parameter which is primarily used for debugging. Setting it to true will the most common usage.
  • paramNames - An array of the names of the incoming parameters.
  • paramValues - An array of the values passed on as parameters. This array should have a perfect correspondence with paramNames.
  • customerNo - optional. The current customer number will be passed along by default.
  • cacheMode - Optional. Numeric.
    0               No caching
    1               Cache is shared by all users
    2 (Default)     Cache per user
    3               Cache for anonymous users
    4               Cache per user, authenticated users only
  • cacheMinutes - Optional. Defaults to 10 minutes.

 

The returned result is returned as a record set (if the 2nd parameter is set to true) from which the values can be picked out, row by row.

Example:

                      var rs = TradePoint.InvokeTP("GETITEM", true, nameArr, valueArr);

            var itemNumber = rs("No.").value;

 

The names of the parameters are specified in the code unit executing the NAV call.

Knowing which NAV code is being executed

To find out which NAV code is being executed at a certain time you can go about in 2 ways - review the ScriptServer template in use or monitor the calls coming to your NAS.

Method 1 - Review the ScriptServer template in use

To find the template in use for a certain page, you either click the Properties icon to see the properties dialog for the current page which will tell you the template it uses or you can also use the System Editor to open the page that's being displayed by looking at the current URL.

In the template code you should most likely find a TradePoint.InvokeTP() call. You might also find it inside one of the Scriptlet calls being made in the template code.

Once you find the InvokeTP-call write down the actionWord parameter and proceed.

Method 2 - Monitor the NAS calls

Since all TradePoint NAV calls are passed through the TradePoint NAS TC code unit, you should monitor this code unit to find out which action words are being passed on. Simply add a MESSAGE() call on the top of the code unit to display which action word was sent in. if you are running the NAS your message will end up in the event log, if you are using the TradePoint MQ Form, you message will be shown as an alert in your NAV client.

If you are running the TradePoint MQ Form you can also use the NAV Debugger to step through the code nice and easily.

Finding the NAV code unit being executed

Once you have the action word, just locate it in the TradePoint NAS TC code unit to find out which code unit and method it invokes.

Adding incoming parameters

Once you have determined which code unit and method is being called, modifying the NAV code to accept new parameters is a simple procedure which should pose no big obstacle to any one comfortable working with C/SIDE.

Remember that you always get the customer no. passed on automatically, so no need to add anything on the ScriptServer end to get that information.

Adding outgoing parameters

To add an outgoing parameter you need to make at least 2 modifications - add the column and add the actual value.

Browsing through the response code you will quickly find that there are 2 major sections in the code - first there is the section where all the column names are specified and then the section where the actual data is being added, line by line.

  • The column names are being used when the data is being retrieved on the ScriptServer end. You can use whatever column names you like, just remember, if you change the column name in NAV, you need to modify all the places in TradePoint where you call this function to look for the new name instead.
  • The data return section is simply returning data in the order you specified in the column section.
    Note that if you need to return large texts, you can utilize the BigText type (NAV 4.0) to concatenate large texts before adding them to the return XML.

Once you have added a new column, compiled the code unit and restarted the NAS, your new data is available to be retrieved in the TradePoint templates.

Adding a new NAV call

You can add as many action words as you like to expand the functionality of TradePoint. Guidelines for this process are described in a separate help article.

 

NAV errors

Identifying a NAV error

NAV errors are usually being displayed as a Windows alert box, showing the NAV error message just the way it would have been displayed inside the NAV client.

Debugging NAV errors

Utilizing the methods described above you should be able to find out which part of your NAV code is being executed at a particular time. The best way to find the exact line of code is of course to turn of the NAS and instead use the TradePoint MQ Form. This allows you to use the debugger and set break points and step through your code line by line.




Published by: Henrik Weimenhög / scriptserver.com
help.scriptserver.com/Tutorials/Developers/TradePoint-CustomizingNAVCalls