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;