Sunday, November 23, 2014

Disable "ESC" Button to close form (Without Codes)



I think this is only small tips and tricks if you want to disable "ESC" button to close form without any codes in Navision. 

I tried to create simple new form with a source data from Customer Cronus, add few fields (textbox), and add 1 transparent button so that user can't see it. This button has "Cancel" Property = Yes.


When I run the form, user is not able to close the form when press "ESC" button.



Happy trying......



Saturday, November 22, 2014

Happiness




"The happiest people don't have the best of everything. They just make the best of everything. Being happy doesn't mean that everything is perfect. It means that you've decided to look beyond the imperfections."
(Unknown)


Wednesday, November 12, 2014

Navision Virtual Tables



How to know the list of Navision Virtual Table without using SQL Script? 
You may use System Object virtual table (ID 2000000029) and show it in form. The form will show the list of Virtual Tables (based on Navision Version) that are not available in Object Designer.

Below picture is using Navision 2009:




Monday, November 10, 2014

Navision Wingdings and Webdings Font List


There is one thing makes me interested in Dashboard form of LS Retail. I found out special font that showing interesting pictures :). It is Wingdings font. It makes me curious to find out more and it may be very useful in my future development.

I create small application to see the list of characters of this font. This listing will make me easier to choose what picture I need in my future development.

Source:

OBJECT Form 50003 Wingdings and Webdings List
{
  OBJECT-PROPERTIES
  {
    Date=11/11/14;
    Time=11:05:43 AM;
    Modified=Yes;
    Version List=MY;
  }
  PROPERTIES
  {
    Width=9790;
    Height=6710;
    Editable=No;
    TableBoxID=1000000000;
    SourceTable=Table2000000026;
    OnOpenForm=BEGIN
                 SETRANGE(Number,0,255);
               END;

    OnAfterGetRecord=BEGIN
                       gChar := Number;
                       gWingdings := Number;
                       gWingdings2 := Number;
                       gWingdings3 := Number;
                       gWebdings := Number;
                     END;

  }
  CONTROLS
  {
    { 1000000000;TableBox;220 ;220  ;9350 ;6270 ;HorzGlue=Both;
                                                 VertGlue=Both;
                                                 RowHeight=1320;
                                                 HeadingHeight=990 }
    { 1000000001;TextBox;291  ;770  ;2200 ;440  ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes;
                                                 SourceExpr=Number }
    { 1000000002;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000001;
                                                 InColumnHeading=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes;
                                                 CaptionML=ENU=Decimal }
    { 1000000022;TextBox;1693 ;660  ;2200 ;440  ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes;
                                                 CaptionML=ENU=Character;
                                                 SourceExpr=gChar }
    { 1000000023;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000022;
                                                 InColumnHeading=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes }
    { 1000000006;TextBox;1693 ;550  ;2200 ;440  ;Name=Wingdings;
                                                 ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 ForeColor=16711680;
                                                 BackColor=16777215;
                                                 FontName=Wingdings;
                                                 FontSize=35;
                                                 CaptionML=ENU=Wingdings;
                                                 SourceExpr=gWingdings }
    { 1000000007;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000006;
                                                 InColumnHeading=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes }
    { 1000000010;TextBox;6377 ;550  ;2200 ;440  ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 ForeColor=128;
                                                 FontName=Wingdings 2;
                                                 FontSize=35;
                                                 CaptionML=ENU=Wingdings 2;
                                                 SourceExpr=gWingdings2 }
    { 1000000011;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000010;
                                                 InColumnHeading=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes }
    { 1000000014;TextBox;9340 ;1540 ;2200 ;440  ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 ForeColor=32896;
                                                 FontName=Wingdings 3;
                                                 FontSize=35;
                                                 CaptionML=ENU=Wingdings 3;
                                                 SourceExpr=gWingdings3 }
    { 1000000015;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000014;
                                                 InColumnHeading=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes }
    { 1000000018;TextBox;13679;440  ;2200 ;440  ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 ForeColor=8388736;
                                                 FontName=Webdings;
                                                 FontSize=35;
                                                 CaptionML=ENU=Webdings;
                                                 SourceExpr=gWebdings }
    { 1000000019;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000018;
                                                 InColumnHeading=Yes;
                                                 FontSize=10;
                                                 FontBold=Yes }
  }
  CODE
  {
    VAR
      gWingdings@1000000001 : Char;
      gWingdings2@1000000002 : Char;
      gWingdings3@1000000005 : Char;
      gWebdings@1000000006 : Char;
      gChar@1000000008 : Char;

    BEGIN
    END.
  }
}

Wednesday, November 5, 2014

Sample Copy Data from Template Table by using RecordRef



Just trying to create this sample for my reference purpose in future. Refer to CU 8611 (Migration Management) and CU 8612 (Template Management) for more detail....
OnRun()
TemplateTable.RESET;
IF TemplateTable.FINDSET THEN REPEAT
  FromRecRef.GETTABLE(TemplateTable);
  ToRecRef.GETTABLE(DestinationTable);
  ToRecRef.INIT;
  FieldRec.SETRANGE(TableNo, FromRecRef.NUMBER);
  FieldRec.SETRANGE(Enabled, TRUE);
  FieldRec.SETRANGE(Class, FieldRec.Class::Normal);
  IF FieldRec.FINDSET THEN BEGIN
    InsertRecordWithKeyFields(ToRecRef,FromRecRef);
    REPEAT
      IF NOT IsKeyField(FieldRec.TableNo,FieldRec."No.") THEN BEGIN
        FromFieldRef := FromRecRef.FIELD(FieldRec."No.");
        ToFieldRef := ToRecRef.FIELD(FieldRec."No.");
        ValidateFieldValue(ToRecRef,ToFieldRef,FORMAT(FromFieldRef.VALUE));
      END;
    UNTIL FieldRec.NEXT = 0;
    ToRecRef.MODIFY(TRUE);
  END;
  CLEAR(FromFieldRef);
  CLEAR(ToFieldRef);
  FromRecRef.CLOSE;
  ToRecRef.CLOSE;
UNTIL TemplateTable.NEXT = 0;
MESSAGE('Done !!!');



ValidateFieldValue(VAR RecRef : RecordRef;VAR FieldRef : FieldRef;Value : Text[250])
Field.GET(RecRef.NUMBER,FieldRef.NUMBER);

IF Field.Type <> Field.Type::Option THEN BEGIN
  IF Value <> '' THEN
    EVALUATE(FieldRef,Value);
END ELSE
  IF GetOption(Value,FieldRef.OPTIONCAPTION,OptionAsInteger) THEN
    FieldRef.VALUE := OptionAsInteger;

FieldRef.VALIDATE;

GetOption(Value : Text[250];OptionString : Text[1024];VAR OptionInteger : Integer) Valid : Boolean
IF Value = '' THEN
  EXIT;
IF EVALUATE(OptionInteger,Value) THEN BEGIN
  EXIT(TRUE);
END;

ValueInOptionString := FALSE;

CommaPos := STRPOS(OptionString,',');

WHILE NOT ValueInOptionString AND (CommaPos > 0) DO BEGIN
  IF STRPOS(OptionString,',') <> 0 THEN
    Option := COPYSTR(OptionString,1,STRPOS(OptionString,',')-1)
  ELSE
    Option := OptionString;
  IF Option = Value THEN
    ValueInOptionString := TRUE
  ELSE
    OptionPos := OptionPos + 1;
  OptionString := DELSTR(OptionString,1,CommaPos);
  CommaPos := STRPOS(OptionString,',');
END;

IF OptionString = Value THEN
  ValueInOptionString := TRUE;

OptionInteger := OptionPos;
EXIT(ValueInOptionString);

InsertRecordWithKeyFields(VAR RecRef : RecordRef;_RecRef : RecordRef)
_KeyRef := _RecRef.KEYINDEX(1);
KeyRef := RecRef.KEYINDEX(1);
FOR KeyFieldCount := 1 TO KeyRef.FIELDCOUNT DO BEGIN
  _FieldRef := _KeyRef.FIELDINDEX(KeyFieldCount);
  FieldRef := KeyRef.FIELDINDEX(KeyFieldCount);
  ValidateFieldValue(RecRef,FieldRef,FORMAT(_FieldRef.VALUE));
END;

RecRef1 := RecRef.DUPLICATE;

IF RecRef1.FIND('=') THEN BEGIN
  RecRef := RecRef1;
  EXIT
END;

RecRef.INSERT(TRUE);

IsKeyField(TableID : Integer;FieldID : Integer) : Boolean
RecRef.OPEN(TableID);
KeyRef := RecRef.KEYINDEX(1);
FOR KeyFieldCount := 1 TO KeyRef.FIELDCOUNT DO BEGIN
  FieldRef := KeyRef.FIELDINDEX(KeyFieldCount);
  IF FieldRef.NUMBER = FieldID THEN
    EXIT(TRUE);
END;

EXIT(FALSE);

Tuesday, October 28, 2014

Action Apply DO

Bruce Lee :

Knowing is not enough, we must apply. Willing is not enough, we must do.

Tuesday, October 21, 2014

Navision Progressbar Pseudocode


I would like to post this pseudocode so that I can refer it anytime and anywhere I want. after many years in Navision world, I feel that I need progressbar everytime I want to know the progress of the data processing. It's tedious action that I need to open my old database to find the codes again and again...... --<--<@


...

CurrTotal := 0;
TotalRecs := <TABLE>.COUNT;
ProgressBar.OPEN('<TITLE> #1#####' + ' / ' + FORMAT(TotalRecs) + '\' +
                 '<FIELD NAME 1>           #2#########'        + '\' +
                 '<FIELD NAME 2>           #3#########'        + '\' +
                 '<FIELD NAME 3>           #4#########'        + '\' +
                 '\@5@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@');
REPEAT

  //PROCESSING......

        
  CurrTotal := CurrTotal + 1;
  Progress := ROUND(CurrTotal/TotalRecs*10000, 1); //max limit = 10000
  ProgressBar.UPDATE(1, CurrTotal);
  ProgressBar.UPDATE(2, <TABLE>.<FIELD NAME 1>);
  ProgressBar.UPDATE(3, <TABLE>.<FIELD NAME 2>);
  ProgressBar.UPDATE(4, <TABLE>.<FIELD NAME 3>);
  ProgressBar.UPDATE(5, Progress);

UNTIL <TABLE>.NEXT = 0;


...


Name            DataTye

========================
Progress Integer
ProgressBar Dialog
TotalRecs Integer
CurrTotal Integer

Thursday, October 2, 2014

Office Assistant in Navision :) :) :)

Moving back to Year 2005....

I was Novice in Navision. I learnt and played with Navision until I created this small application and posted it to Mibuso (http://www.mibuso.com/dlinfo.asp?FileID=500)


Nostalgia Mode = ON.......:) :) :)

"When starting a program in Windows 7, you may receive an error associated with Microsoft Agent, after receiving the error message the program may crash."

There is hotfix to fix this:
https://support.microsoft.com/kb/969168?wa=wsignin1.0

Wednesday, October 1, 2014

Few Methods to do Custom Control Lookup

This is sample codes to do lookup to Customer List form and put the lookup value to field "TableField"


TableField - OnLookup (VAR Text : Text[1024;) : Boolean
Method 1:
CLEAR(CustForm);
CustTable."No." := Text;
CustTable.SETRANGE("No.",'10000','50000');
CustForm.SETTABLEVIEW(CustTable);
CustForm.SETRECORD(CustTable);
CustForm.LOOKUPMODE(TRUE);
IF CustForm.RUNMODAL = ACTION::LookupOK THEN BEGIN
  CustForm.GETRECORD(CustTable);
  TableField := CustTable."No.";
END;

Method 2:
CustTable."No." := Text;
CustTable.SETRANGE("No.",'10000','50000');
IF FORM.RUNMODAL(0,CustTable) = ACTION::LookupOK THEN

  "Test Lookup" := CustTable."No.";

Method 3:
CustTable."No." := Text;
CustTable.SETRANGE("No.",'10000','50000');
IF FORM.RUNMODAL(0,CustTable) = ACTION::LookupOK THEN BEGIN
  Text := CustTable."No.";
  EXIT(TRUE);

END;

How to check table's value changes dynamically

 _RecRef.GETTABLE(Rec);
 _xRecRef.GETTABLE(xRec);

ValueChanged := FALSE;
Field.SETRANGE(TableNo,_VarRecRef.NUMBER);
Field.SETFILTER(Type,'<>%1',Field.Type::TableFilter);
Field.SETRANGE(Enabled,TRUE);
IF Field.FIND('-') THEN
  REPEAT

    NewFieldRef := _VarRecRef.FIELD(Field."No.");
    OldFieldRef := _xVarRecRef.FIELD(Field."No.");
    IF NewFieldRef.VALUE <> OldFieldRef.VALUE THEN BEGIN
         MESSAGE('OLD VALUE = %1, NEW VALUE = %2, FIELD NO = %3',                                                                OldFieldRef.VALUE, NewFieldRef.VALUE, Field."No.");
      ValueChanged := TRUE;
    END;

  UNTIL (Field.NEXT = 0) OR (ValueChanged = TRUE);
EXIT(ValueChanged);

Dynamic Table by using RecordRef


_RecordRef.CLOSE;
_RecordRef.OPEN(_YourTableNumber);
IF _RecordRef.FINDSET THEN
  REPEAT
    _FieldRec.SETRANGE(TableNo, _RecordRef.NUMBER);
    _FieldRec.SETRANGE(Enabled, TRUE);
    _FieldRec.SETRANGE(Class, _FieldRec.Class::Normal);
    IF _FieldRec.FINDSET THEN
      REPEAT
        _FieldRef := _RecordRef.FIELD(_FieldRec."No.");
        MESSAGE(FORMAT(_FieldRef.VALUE));
      UNTIL _FieldRec.NEXT = 0;
  UNTIL _RecordRef.NEXT = 0;

CLEAR(_FieldRef);
_RecordRef.CLOSE;

Good Article How to use RecordRef, FieldRef, and KeyRef

Good Article from Emiel Romein



OnRun()
// Unmark as text to test code.

SearchString := 'can';

//Search(DATABASE::Contact,SearchString);
//Search(DATABASE::Customer,SearchString);
//Search(DATABASE::Vendor,SearchString);

//CountRecords;

//MESSAGE(KeyName(DATABASE::"Sales Header"));



Search(TableNo : Integer;String : Text[30])
// This little sample of code will search for a record that matches a filter. In this case it will search either Contact, Customer
// or Vendor for a record that matches the string filter on the Search Name field.

SearchFieldNo := 3; // This is the number of the Search Name field in tables Contact, Customer and Vendor.

SearchIn.OPEN(TableNo); // Create an RecRef referring table with same number as var TableNo. Can be any table in Navision.

//SearchIn.OPEN(DATABASE::Customer,true); // Open a temporary RecRef. Nice fact, this fieldref does not contain any records.
//SearchIn.open(database::customer,false,CompName); // Open a RecRef in another company.

SearchInFld := SearchIn.FIELD(SearchFieldNo); // Create an FieldRef of a field in the table opened above.
SearchInFld.SETFILTER('%1',STRSUBSTNO('@*%1*',String)); // Place a filter on the FieldRef.
                                                        //  @ = Non case sensitive, *%1* = Any part of field.

// Becaurse SearchInFld is referring to the same table as SearchIn, every filter that is placed using this FieldRef also applies
// to the RecordRef.
// To be short, I can now see if records exist within filters.

SearchIn.FIND('-');

// Off course you can now loop the RecRef using repeat's, until's and next's

// Unfortunately it is not possible to open forms based on recordref's. So if you want to show a list of records found, you will
// have to program a form.open for each possible search record. See below for a sample.

CASE TableNo OF
  DATABASE::Customer :
  BEGIN
    Customer.SETVIEW(SearchIn.GETVIEW); // Use this function to set the current sort order, key and filters on a table.
    FORM.RUNMODAL(0,Customer); // Make is a lookup if you want to be able to select a record.
  END;
  ELSE
    ERROR(Text000);
END;



CountRecords()
// This little sample of code will count the records in a table using only one variable.

Object.SETRANGE(Type,Object.Type::Table); // Only Tables have records. What?! You didn't know that?
Object.SETRANGE(Object.ID,1,10); // For this sample, count only records in tables 1..10.
Object.FIND('-'); // IF THEN? Hopefully you have some object in your database!

REPEAT
  Table.OPEN(Object.ID); // Open Record reference to current table.

  MESSAGE(Text000,Object.Name,Table.COUNT); // Show you what was found.
UNTIL Object.NEXT = 0;



KeyName(TableNo : Integer) KeyString : Text[1024]
// This little sample of code will return the name of a key of any table in Navision.

KeyNo := 1; // Keynumber of wich we want to get the name.

Table.OPEN(TableNo); // Create a record reference to a table.
Key := Table.KEYINDEX(KeyNo); // Create a key reference to the key we want to get the name from.

IF NOT Key.ACTIVE THEN // Don't do anything if the key is not active. But you could if you want to.
  EXIT;

FOR i := 1 TO Key.FIELDCOUNT DO BEGIN // Run this loop as much times as there are fields in this key.
  Field := Key.FIELDINDEX(i); // Create a fiel reference to the (#i) field in the key.
  KeyString := STRSUBSTNO('%1%2%3',KeyString,Separator,Field.NAME); // Create a string wich sums all key fields, using the fieldref
                                                                    // name as field name.
  Separator := ',';
END;

Friday, September 26, 2014

Pseudocode to create multiple sheets in Excel

With ExcelBuf Do Begin
  SetUseInfoSheed;
  AddInfoColumn ('Company Name',False,'',True,False,False,'');
  AddInfoColumn (CompanyName,False,'',False,False,False,'');
  ClearNewRow;
  NewRow;
  AddColumn ('Sheet',False,'',True,False,False,'');
  AddColumn ('#1',False,'',True,False,False,'');
  CreateBook;
  CreateSheet('#1','Test Excel',CompanyName,UserID);
  DeleteAll(False);
  ClearNewRow;
  NewRow;
  AddColumn('Sheet',False,'',True,False,False,'');
  AddColumn('#2',False,'',True,False,False,'');
  CreateSheet('#2','Test Excel',CompanyName,UserID);
  DeleteAll(False);
  GiveUserControl;
END;


Source : http://dynamicsuser.net/forums/p/23242/120607.aspx

Thursday, May 29, 2014

Navision SMTP Error


We encountered intermittent error in Navision related to SMTP Mail.












Troubleshooting steps:



  1. In Windows Command, run nslookup
  2. <smtp mail server name>.<company domain>. This is FQDN
  3. Check if DNS Server is able to show the IP Address
  4. If can't show the IP Address, try to add DNS Suffix in IPV4 and try to run Navision application again
  5. If the problem persisted, try to ping <smtp mail server name> and if it's failed, most likely it's windows issue (guess...)

Resolution :
--> Change SMTP Mail Server name in Navision SMTP Mail Setup to IP address.