Labels

Friday, November 11, 2011

How to decide certain value satisfy filter conditions or not?

Imagine, you have the special field in setup table for defining filter conditions. It could contain a range of items or customers and looks like "C1000..C2000|C2500".
Now, when you proceeding certain record you would like to know, does the "No." of your record satisfies filter conditions or not. I think better way for this is to use filters:
   CustomersL.SETFILTER( "No.", '(%1)&%2', SetupL."Filter Conditions", ProceedingNo);
   IF CustomersL.FINDFIRST THEN MESSAGE('Record satisfies filter');
I hope this little tip would be useful.

Wednesday, October 12, 2011

Convenient way to add new records by copying its parameters from template

I think it would be very convenient if we could use Data Templates when creating new record.
This way users shouldn't do fool mistakes on filling some mandatory fields like posting groups, location codes etc.

Let's take for example Item table.

There are several issues why we can't use Form - OnNewRecord and Form - OnInsertRecord triggers. In the first case we can't insert new record, because the transaction could not be started there. In the second case 2 records would be created, 1st record is copied from template and 2nd is inserted with empty fields in a standard way.

That's why I've created new menubutton with F3 shortcut on Customer Card. This button should intercept event of creating item (pressing F3 key). The code of trigger is below:

Tuesday, September 27, 2011

Incremental SSIS package template

Some time ago I was engaged in building Data Warehouse (DWH) for NAV database. To develop incremental data transfer I used system field timestamp, which is present in every NAV table. I build the table, called Timestamp Settings in DWH with the following structure:
Where CompanyID is the index of NAV company in DWH.
When the SSIS package launches, the script task, which reades the last timestamp values, is fired.

Tuesday, July 19, 2011

Using web-service to send SMS from NAV

Recently I had a task to send SMS notification through the Webservice.
My service provider use following interface protocols.
Request for sending SMS:
Where:
  • login and password are the authentication parameters;
  • id is the internal message ID;
  • recipient is the mobile phone number of the recipient;
  • sender is a sender description;
  • text is a message text.
This request should be posted to a webservice via HTTP or HTTPS.

Tuesday, July 12, 2011

Item lookup with built-in search

Let's take a look at the operations, that manager executes every time he adds new item to an order:
1. Pushes lookup in the No. field
2. Goes to a Description field and starts to write an item name.
3. Chooses a necessary item.
If a user knows an Item name, then he can write it directly in No. field. NAV will search for an Item, that begins with an entered phrase and insert it's code to a No. field. It is because of AltSearchField property, setted for the Item table.
But what if several items, which Description field contains entered phrase exists? NAV will find only first of them... It's not convinient and that's why users prefer searching items in the item list, spending more time for every line.

My suggestion is to let the user choose an item from a list, if there are several items, that complies his request. It's a kind like incadea does...

Subform detail or summary view

Often there is so many fields on a subform, that user become confused. It's a standard Navision way, that user can customize those fields, that he wants to view on the subform. But, I think, more user-friendly is to have a button, that switches from summary view to details if user wants to enter extra-data.
Lets take for example Sales Order. I've created 2 buttons, place them on each other below the subform: bSum & bDetails.
bSum is not Visible by default (property Visible = No), it means the Summary view will be shown by default and user can switch to Details.

Saturday, July 9, 2011

Using LumiSoft.Net for retrieving e-mail from Dynamics NAV

Recently, I've found great library for net handling (POP, SMTP, FTP, HTTP and others) - LumiSoft.Net http://www.lumisoft.ee/lsWWW/download/downloads/Net/LumiSoft.Net.zip
Here is the link to the help index for that library http://www.lumisoft.ee/lswww/download/downloads/Net/Help/. Exciting!
It's open source (C# .NET) and completly free for modifing and using in commercial projects. Wonderfull, many thanks to it's author!
So, I was engaged in using this library in Dynamics NAV.

First of all, this library should be compiled as COM Automation object. For this possibility:
1) COM Interop on the project tab should be checked.
2) Special attributes for COM sharing should be appointed for the classes:
[ComVisible(true), ClassInterface(ClassInterfaceType.AutoDual),Guid(" ... ")]
Namespace System.Runtime.InteropServices should be used.
3) GUID for assembly should be appointed:
[assembly: Guid(" ... ")]
4) some classes should be redesigned (for example, static members are not visible in COM)

If Guids are not appointed that way, the linker automatically creates it, but every time you making changes in the source code you would have new Guids. It's too difficult for parallel NAV debugging, because C\AL variables are droped after new COM server is registered. The description "Unknown Automation Server.Unknown Class" is shown in that case.
I used special tool for Guid creation (Tools - Create Guid in Visual Studio).

In Dynamics NAV I've created a pair of simple tables (Message and Mailbox). Message have a table relation to Mailbox:

Friday, June 24, 2011

Simple way to store password in database

Imagine, you want to store user password to access external NAV portal, and no one must see it.
You can, of course, set the property to PasswordText  = Yes on the form. But, what if the user press Ctrl + F8 to view fields inside the table? ...
So, let's write a little function to store protected password text.

Password - OnValidate()
Password := EncodeDecode(Password);



EncodeDecode(String : Text[30]) : Text[30]
FOR i := 1 TO STRLEN(String) DO
BEGIN
  Ch := String[i];
  Pass[i] := 255-Ch;
END;
EXIT(Pass);

So, you can use this function not only for encoding text, but also for decoding.

Wednesday, June 22, 2011

Using .NET COM object for sending e-mails or SMS in NAV

As we all know standard MAPI interface, provided in NAV, works only when mail client (like Outlook Express or Outlook) is installed. There are several issues why this approach is not suitable. I decided to develop my own COM object to work directly with SMTP server.

My .NET COM wrapper for System::Net::Mail::SmtpClient consist of 3 main files:

  • SMTPClient.idl - interface definition;
  • SMTPMessage.h - header file;
  • SMTPMessage.c - source code;
New .NET COM class should provide methods to define parameters:
  • Sender e-mail address & sender name (shown in message, field From);
  • Receiver e-mail address & receiver name (shown in message, field To);
  • Server name, port and flag for using SSL protocol;
  • User name & password for authentication.
Total source project directory you can download here: https://sites.google.com/site/9ri331y/SMTPClient.sources.zip


Please, post a feedback if you find this project useful for you.

SMTPClient.idl list:

// SMTPClient.idl : IDL source for SMTPClient
import "oaidl.idl";
import "ocidl.idl";

Tuesday, June 21, 2011

Implementing interactive picture in NAV

Some time ago I was solving the task to print some interactive picture inside the NAV report. It means that user should draw some picture, import the picture in the document and then print it. The picture should be imported in NAV database to have an opportunity to re-print the document later.
Sub-task of producing Macromedia Flash presentation in which user can draw something was given to an outsource. This program was compiled like an ordinary exe-file, input parameter for it was a name of file to save the result (in bitmap format, of course).
When producing of this program was completed additional triggers were implemented:

InputVehiclePicture()


ServSetup.GET();
ServSetup.TESTFIELD( "Import Vehicle Picture Dir" );
ServSetup.TESTFIELD( "Import Vehicle Picture Command" );
IF COPYSTR( ServSetup."Import Vehicle Picture Dir", STRLEN( ServSetup."Import Vehicle Picture Dir" ), 1 ) <> '\' THEN
  ServSetup."Import Vehicle Picture Dir" := ServSetup."Import Vehicle Picture Dir" + '\';


FileL := ServSetup."Import Vehicle Picture Dir" + "No." + '.bmp';

Parameter Setup

Usually I face a problem, that some constants should be stored in database. For example, complex report should be run and a hundreds of filters should be setted up. When running report user should have friendly interface with the number of parameters, that he can change (for example, date range), other filters should be not visible for him, but available for support. That's why I've created special table with simple structure:
1 Object Type      Option
2 Object           Integer
3 Parameter ID     Code[30]
4 Value            Text [250]  

Object ID field is related to Object table.
This flexible table allows not only setup parameters for reports, but for dataports and forms, too.

Also, the benefit is that it is not neccessary to add fields in standard Setup tables - less standard database modification.

In the conclusion let me bring a code for reading the parameter from this table, it is very simple:
ReportParameterSetup.GET(ReportParameterSetup."Object Type"::Report, 50163, 'CurrencyGUID');
CurrencyGUID := ReportParameterSetup.Value; 

Web service for Dynamics NAV (server-side)

Today I would like to discuss with you how to implement a Web service for Dynamics NAV and to interact with this service from Dynamics NAV C/SIDE Client or even web server.

My target was to build a NAV database (because employees are used to work with it's interface) with online access. In this online database additional information about customers (such as bonus balance) should be stored. Information about customer bonus balance should be available not only in NAV working database, but in internet, too. Further more, when posting a discount in NAV operational database, customer bonus balance should be reduced.

From the system point of view, the Navision Application Server, connected to bonus database, should be started. Certain TCP ports should be opened. When the message come to this port some event should be triggered, and a response should be posted back. The language for this interaction should be XML.

Codeunit 1, Trigger 99 NASHandler(ATASID : Text[260])
GenSetupL.GET;
GenSetupL.TESTFIELD("NAS Application Port");
IF ISCLEAR(CC) THEN CREATE(CC);
IF ISCLEAR(SBA) THEN CREATE(SBA);
CC.AddBusAdapter(SBA, 0);
SBA.OpenSocket(GenSetupL."NAS Application Port", '');
MESSAGE(StartedNASTxt, GenSetupL."NAS Application Port");

where
CC Automation 'Navision Communication Component version 2'.CommunicationComponent
SBA Automation 'Navision Socket Bus Adapter'.SocketBusAdapter
are the global variables. After adding CC variables the new trigger was created automaticly:
CC::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
Then the new trigger for proceeding incoming request was created and the next code was added:

Interaction with Web service from NAV client-side

So, next task is to send the request from NAV Client. To complete this task I used  'Microsoft XML, v6.0'.XMLHTTP automation object.


SendRequest()
IF ISCLEAR(XMLDoc) THEN 
  CREATE(XMLDoc);
IF ISCLEAR(XMLResponse) THEN
  CREATE(XMLResponse);


RequestText := SOAPBegin + '<Request method="GetBalance" ' + SOAPSchema + '>' +
'<CardID>' + CardID + '</CardID>' +
'</Request>' + SOAPEnd;


IF NOT XMLDoc.loadXML(RequestText) THEN ERROR(RequestFailed);


IF ISCLEAR(HTTPL) THEN
  CREATE(HTTPL);
HTTPL.open('POST',CRMSetup."Bonus Server Url",FALSE);
HTTPL.setRequestHeader('Content-Type','text/xml');
HTTPL.setRequestHeader('SOAPAction','');
HTTPL.send(RequestText);


XMLResponse := HTTPL.responseXML;
IF HTTPL.status <> 200 THEN ERROR(ConnectionFailed);
IF ISCLEAR(XMLResponse) THEN ERROR(ConnectionFailed);


DocRoot := XMLResponse.documentElement;
XMLDocNode := DocRoot.selectSingleNode('Error');
IF NOT ISCLEAR(XMLDocNode) THEN ERROR(XMLDocNode.text);
XMLDocNode := DocRoot.selectSingleNode('TotalBalance');
IF ISCLEAR(XMLDocNode) THEN ERROR(ProtocolError);
EVALUATE(TotalBalance, CONVERTSTR(XMLDocNode.text,'.',','));