TableRelation OnLookup & Item Journal Batch (Table 233)

Dan84Dan84 Member Posts: 3
I've got a custom table that isn't mapping a column properly.

The field need to be Item Journal Batches (where the Journal Template Name is PHYS. INV.). I can't seem to map these properly to table 233. I say this because when I try to use the lookup on the fields, it only provides me the options of Journal Template CONSUMPTION. After testing I realized the only reason I'm getting the Journal Template CONSUMPTION batches is that CONSUMPTION is the first alphabetically. (e.g. If I created some Journal Template CAPACITY batches, only these would show instead of CONSUMPTION as CAPACITY is first alphabetically).

At first I tried using tableRelation field on these custom fields like such:
"Item Journal Batch".Name WHERE (Journal Template Name=CONST(PHYS. INV.))
After searching this forum some, I thought I'd give code a try, so I did the following:
recItmJnlBatch.RESET;
recItmJnlBatch.SETRANGE("Journal Template Name",'PHYS. INV.');
IF FORM.RUNMODAL(262, recItmJnlBatch) = ACTION::LookupOk THEN BEGIN
  "Phys. Inv. Journal Batch" := recItmJnlBatch.Name;
END;

Despite both of these tries, neither yielded any change to the result set presented in the lookup window.

I then decided to see if I could just get the whole list to show, I cleared out the code and set the TableRelation to just "Item Journal Batch". Yet again, I received only the CONSUMPTION entries.

Am I missing something? I've spent far more time on this than I feel it should take, so I appreciate any help provided.

Comments

  • David_SingletonDavid_Singleton Member Posts: 5,479
    Use the debugger. There is code on the form that changes the filters, and this is probably interfering with what you are trying to do.
    David Singleton
  • Dan84Dan84 Member Posts: 3
    Using the debugger yields the following actions:
    {Object Type/#} - Method Name: Description of task & thoughts
    • {Form/262} - OnInit: Set's range to "Journal Template Name". There's nothing defined at this point so I'm not sure how it would know what to define "Journal Template Name" to. Specifically the Rec variable is empty.
    • {Form/262} - OnOpenForm: Runs the OpenJnlBatch method for Rec. Rec is defined (before call) as the first name alphabetically of the first alphabetically Journal Template Name.
    • {Codeunit/240} - OpenJnlBatch: Checks if current filters exist, if not (which is none at this point) it finds the first record and then uses this to determine the Journal Template and thus filters on this found record's Journal Template. This would appear to be the problem.

    With this information, I tried a simple test, right before the call to CU 240 I added the following line:
    SETFILTER("Journal Template Name", 'PHYS. INV.');
    

    It now works appropriately. Obviously this isn't a good practice, as anything that uses this form will now get the PHYS. INV. batches instead of the first alphabetically.

    I took a step back and tried to reason through where this should go. It belongs at the table level because it doesn't matter where someone wants to set this field, they will always only want the PHYS. INV. batches. It looks like back to the code I wrote originally. I took a look and saw that I used SETRANGE instead of SETFILTER, surely it can't be that simple/stupid (depending how you look at it). So I tried with the following code in the field's OnLookup event:
    recItmJnlBatch.RESET;
    recItmJnlBatch.SETFILTER("Journal Template Name",'PHYS. INV.');
    IF FORM.RUNMODAL(262, recItmJnlBatch) = ACTION::LookupOK THEN BEGIN
      "Phys. Inv. Journal Batch" := recItmJnlBatch.Name;
    END;
    

    No such luck. It still returns the wrong set. Debugging the code again, it looks the exact same as above (minus my code which appears to filter the records as desired), that is, no record is present for any of the steps, so the first one is grabbed and used for filtering. It appears one of two things is happening, either I'm missing something critical that allows for my information to be used for filtering, or the Item Journal Batch was written in a way to prevent any sensible way to filter down the selections appropriately.

    Any help is greatly appreciated.


    EDIT: The following information is what I've since figured out which may provide additional useful information.

    I have found that there is more to the following steps than I originally thought:
    • {Form/262} - OnInit: Set's range to "Journal Template Name". There's nothing defined at this point so I'm not sure how it would know what to define "Journal Template Name" to. Specifically the Rec variable is empty.

    In the first step, although none of the field values are passed through, the filter values are passed. The SetRange("Journal Template Name") is clearing this setting right away. This happens in the step above. With this in mind, if I comment it out, it appears to work as expected.

    I did some searching for any information on why this line of code exists but I can't seem to find any. Is it going to be a problem if I comment this out? I'm concerned that this is there for a reason and that the change I'm making is going to break a different workflow.
Sign In or Register to comment.