Labels

Monday, June 3, 2013

Universal XML export

Few days ago I had a task to export some records (about 20 tables related) in XML.
I'd prefer to write some kind of universal export procedure, rather than proceed with every table.

So, at first, after running we should read the settings from the file, which will be located in the same location as the result export file. Every line in the file should be as follows: TableNo [Tab] FieldNo, meaning that this field should be exported to XML.
The procedure for reading this file should be like this:

ReadSettings()
DlgStatus.UPDATE(1, StatusReadSettings);
SettingFile.TEXTMODE(TRUE);
SettingFile.WRITEMODE(FALSE);
SettingFile.OPEN(ExportPath + 'mapping.txt');
REPEAT
  SettingFile.READ(SettingString);
  i := 1;
  CLEAR(Index);
  WHILE i <= STRLEN(SettingString) DO BEGIN
    Symbol := COPYSTR(SettingString,i,1);
    IF STRPOS('0123456789',Symbol) <> 0 THEN BEGIN
      IF (Index[1] = 0) THEN Index[1] := i;
      IF (Index[2] <> 0) AND (Index[3] = 0) THEN Index[3] := i;
    END ELSE BEGIN
      IF (Index[1] <> 0) AND (Index[2] = 0) THEN Index[2] := i;
    END;
    i += 1;
  END;
  EVALUATE(Mapping[1], DELCHR(COPYSTR(SettingString,Index[1],Index[2]-Index[1]),'<>', ' '));
  EVALUATE(Mapping[2], DELCHR(COPYSTR(SettingString,Index[3],STRLEN(SettingString)-Index[3]+1),'<>', ' '));
  ExportFields.INIT;
  ExportFields.TableNo := Mapping[1];
  ExportFields."No." := Mapping[2];
  ExportFields.INSERT;
UNTIL SettingFile.POS = SettingFile.LEN;
where ExportFields is the temporary table, based on the table 2000000041 Field.

Next, I've prepared the core function to export whatever record:

Friday, September 28, 2012

Simple notification service

In Microsoft Dynamics NAV 2009 platform new triggers OnDatabaseInsert, OnDatabaseModify, OnDatabaseDelete, OnDatabaseRename were added. They are fired even in code you don't call triggers  INSERT, MODIFY, DELETE with TRUE arguement. In standard functionality these triggers are used for integration with Microsoft Dynamics CRM product.
The Business Notification Server functionality is too complex and requires some additional granules, that costs some money. So, I 've created the alternative lightweight universal solution for notification. IT manager has the possibility to subscribe user for special events on any table. And user will get notification in his mailbox.

Thursday, March 29, 2012

Converting docx file to stylesheet


From NAV version 5.0 here's the possibility to send forms to Word/Excel. This functionality uses progressive XSLT technology, which uses source XML file with data + XSLT file with view template.
There is special tool to make the process of using templates much easier. See http://www.mibuso.com/dlinfo.asp?FileID=869 for additional info. But unfortunately this don't works for me. 
I prefer to investigate the manual creation of XSLT from source DOCX file. It's very important to use Word 2007 - 2010 and DOCX extension, because it's represents by XML file.
1. Firstly we should do the "bookmarks" in source text, where we want to export some values, e.g. fldVIN in the location, where's VIN should be.
2. Save DOCX file. Change the extension to ZIP. Inside archive find the file document.xml and copy it to initial folder.
3. Open the document.xml in notepad editor and replace text at the start of file (from the beggining to the tag <w:body>):

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.