Labels

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';