Validation code is executed in the subform

Cem_KaraerCem_Karaer Member Posts: 281
Hello,

I design a form based on a custom table. The table was designed to contain data about physically coming items to a warehouse. A mobile terminal is used to capture the bar-code of an item and to enter the actual quantity. The actual quantities are checked against the shipment documents. If an item is entered with more quantity than it's recorded shipment quantity then a surplus line is created for this item in the custom table.

The shipments are organized in parties. In party A (A for the sake of clarity) some items may come as surplus but in party B their shipment documents may come aftermath. In this perspective, item X may be surplus in Party A but deficient in Party B. These surpluses and deficients must be balanced in a worksheet. So this form (finally :D) is for this work.

The form shows surplus lines and the subform shows Bin Content table because deficient quantities are stored in a bin called 'FARKLAR'. The SubFormLink property of the subform control is Item No.=FIELD(Item No.). The detailed code of the custom form is as follows:
OBJECT Form 50040 Surplus Missing Mapping
{
  OBJECT-PROPERTIES
  {
    Date=11.12.10;
    Time=11:35:44;
    Modified=Yes;
    Version List=Parge;
  }
  PROPERTIES
  {
    Width=16500;
    Height=12430;
    Editable=No;
    CaptionML=[ENU=Surplus Missing Mapping;
               TRK=Eksik Fazla EŸleŸtirme];
    InsertAllowed=No;
    DeleteAllowed=No;
    ModifyAllowed=No;
    TableBoxID=1000000000;
    SourceTable=Table50010;
    SourceTableView=SORTING(Status)
                    WHERE(Status=CONST(Surplus));
  }
  CONTROLS
  {
    { 1000000000;TableBox;220 ;220  ;16060;5500 ;HorzGlue=Both;
                                                 VertGlue=Both }
    { 1000000001;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Party No." }
    { 1000000002;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000001;
                                                 InColumnHeading=Yes }
    { 1000000003;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Item No." }
    { 1000000004;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000003;
                                                 InColumnHeading=Yes }
    { 1000000005;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Actual Quantity" }
    { 1000000006;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000005;
                                                 InColumnHeading=Yes }
    { 1000000007;TextBox;0    ;0    ;4400 ;0    ;HorzGlue=Both;
                                                 ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Item Description" }
    { 1000000008;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000007;
                                                 InColumnHeading=Yes }
    { 1000000009;TextBox;0    ;0    ;550  ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr=Status }
    { 1000000010;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000009;
                                                 InColumnHeading=Yes }
    { 1000000011;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Enter Date" }
    { 1000000012;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000011;
                                                 InColumnHeading=Yes }
    { 1000000013;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Entry No." }
    { 1000000014;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000013;
                                                 InColumnHeading=Yes }
    { 1000000015;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Party Line No." }
    { 1000000016;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000015;
                                                 InColumnHeading=Yes }
    { 1000000017;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Found Party No." }
    { 1000000018;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000017;
                                                 InColumnHeading=Yes }
    { 1000000019;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Found Surplus Qty." }
    { 1000000020;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000019;
                                                 InColumnHeading=Yes }
    { 1000000021;CommandButton;9240;11660;2200;550;
                                                 HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Default=Yes;
                                                 PushAction=LookupOK;
                                                 InvalidActionAppearance=Hide }
    { 1000000022;CommandButton;11660;11660;2200;550;
                                                 HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Cancel=Yes;
                                                 PushAction=LookupCancel;
                                                 InvalidActionAppearance=Hide }
    { 1000000023;CommandButton;14080;11660;2200;550;
                                                 HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 PushAction=FormHelp }
    { 1000000024;SubForm;220  ;5940 ;16060;5500 ;HorzGlue=Both;
                                                 VertGlue=Bottom;
                                                 Editable=No;
                                                 Border=No;
                                                 SubFormID=Form50041;
                                                 SubFormView=SORTING(Location Code,Bin Code,Item No.,Variant Code,Unit of Measure Code)
                                                             WHERE(Location Code=CONST(MERKEZ),
                                                                   Bin Code=CONST(FARKLAR));
                                                 SubFormLink=Item No.=FIELD(Item No.) }
  }
  CODE
  {

    BEGIN
    END.
  }
}
The code of the subform is as follows:
OBJECT Form 50041 Missing Quantities Subform
{
  OBJECT-PROPERTIES
  {
    Date=11.12.10;
    Time=11:43:02;
    Modified=Yes;
    Version List=Parge;
  }
  PROPERTIES
  {
    Width=16060;
    Height=5500;
    Editable=No;
    InsertAllowed=No;
    DeleteAllowed=No;
    ModifyAllowed=No;
    TableBoxID=1000000000;
    SourceTable=Table7302;
  }
  CONTROLS
  {
    { 1000000000;TableBox;0   ;0    ;16060;5500 ;HorzGlue=Both;
                                                 VertGlue=Both }
    { 1000000001;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Location Code" }
    { 1000000002;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000001;
                                                 InColumnHeading=Yes }
    { 1000000003;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Zone Code" }
    { 1000000004;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000003;
                                                 InColumnHeading=Yes }
    { 1000000005;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Bin Code" }
    { 1000000006;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000005;
                                                 InColumnHeading=Yes }
    { 1000000007;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Item No." }
    { 1000000008;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000007;
                                                 InColumnHeading=Yes }
    { 1000000009;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Bin Type Code" }
    { 1000000010;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000009;
                                                 InColumnHeading=Yes }
    { 1000000011;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Warehouse Class Code" }
    { 1000000012;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000011;
                                                 InColumnHeading=Yes }
    { 1000000013;TextBox;0    ;0    ;550  ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Block Movement" }
    { 1000000014;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000013;
                                                 InColumnHeading=Yes }
    { 1000000015;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Min. Qty." }
    { 1000000016;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000015;
                                                 InColumnHeading=Yes }
    { 1000000017;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Max. Qty." }
    { 1000000018;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000017;
                                                 InColumnHeading=Yes }
    { 1000000019;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Bin Ranking" }
    { 1000000020;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000019;
                                                 InColumnHeading=Yes }
    { 1000000021;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr=Quantity }
    { 1000000022;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000021;
                                                 InColumnHeading=Yes }
    { 1000000023;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Pick Qty." }
    { 1000000024;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000023;
                                                 InColumnHeading=Yes }
    { 1000000025;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Neg. Adjmt. Qty." }
    { 1000000026;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000025;
                                                 InColumnHeading=Yes }
    { 1000000027;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Put-away Qty." }
    { 1000000028;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000027;
                                                 InColumnHeading=Yes }
    { 1000000029;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Pos. Adjmt. Qty." }
    { 1000000030;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000029;
                                                 InColumnHeading=Yes }
    { 1000000031;CheckBox;0   ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 ShowCaption=No;
                                                 SourceExpr=Fixed }
    { 1000000032;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000031;
                                                 InColumnHeading=Yes }
    { 1000000033;CheckBox;0   ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 ShowCaption=No;
                                                 SourceExpr="Cross-Dock Bin" }
    { 1000000034;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000033;
                                                 InColumnHeading=Yes }
    { 1000000035;CheckBox;0   ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 ShowCaption=No;
                                                 SourceExpr=Default }
    { 1000000036;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000035;
                                                 InColumnHeading=Yes }
    { 1000000037;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Variant Code" }
    { 1000000038;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000037;
                                                 InColumnHeading=Yes }
    { 1000000039;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Qty. per Unit of Measure" }
    { 1000000040;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000039;
                                                 InColumnHeading=Yes }
    { 1000000041;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Unit of Measure Code" }
    { 1000000042;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000041;
                                                 InColumnHeading=Yes }
    { 1000000043;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Lot No. Filter" }
    { 1000000044;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000043;
                                                 InColumnHeading=Yes }
    { 1000000045;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Serial No. Filter" }
    { 1000000046;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000045;
                                                 InColumnHeading=Yes }
    { 1000000047;TextBox;0    ;0    ;2200 ;0    ;ParentControl=1000000000;
                                                 InColumn=Yes;
                                                 SourceExpr="Available Quantity" }
    { 1000000048;Label  ;0    ;0    ;0    ;0    ;ParentControl=1000000047;
                                                 InColumnHeading=Yes }
  }
  CODE
  {

    BEGIN
    END.
  }
}
There may be redundant fields.

So here is the problem (finally :D):
When browsing the lines, the form sometimes flashes the following error:

Microsoft Dynamics NAV
You cannot modify the Item No., because the Bin Content contains items.
OK

This error is thrown in the OnValidate trigger of Item No. field of the Bin Content table. The subform control tries to validate the Item No. field of the Bin Content table. Why? And how can I prevent this?

The platform: Version TR Dynamics NAV 5.0 SP1 Build 26084
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005

Comments

  • Cem_KaraerCem_Karaer Member Posts: 281
    Hello,

    I haven't been able to find the reason but I made a workaround for this problem. I created a static codeunit and use a boolean variable in it as a global variable by declaring get and set functions for the variable. When the custom form opens I set the variable TRUE and when it closes FALSE. In the OnValidate trigger of the Item No. of the Bin Content, I firstly control the value of the global variable, if it is TRUE then I exit the trigger.

    It is clearly a workaround. If anybody knowns the reason of this behavior I welcome the answer :) . For that reason I leave the topic as unsolved.
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
Sign In or Register to comment.