newbie question!

nvermanverma Member Posts: 396
I have a form. Within the form I have a subform. Subfrom has two two primary key fields (FA No, Depreciation Book Code).

In the Header there is a field called FA Class Code. Whatever the user sets the FA Class Code to, it should automatically set a field in the subform (FA Posting Group) to the exact same thing. I was trying to do an implementation for this.

Code in "FA Class Code" onValidate trigger
FA.GET("No.");
//FADeprBook.SETCURRENTKEY("FA No.");
FADeprBook.GET(FA."No.");
FADeprBook."FA Posting Group" := FA."FA Class Code";
FADeprBook.MODIFY;

This code does not work, because I am using an GET statement, but i am only supplying it one of the primary key fields. I cannot put "Depreciation book code" because it doesnt exists in the header.
Is there a way of forcing the system to only consider one of the primary key fields? I tried the setcurrentkey, but that didnt work. Initially I was trying to do a setfilter (FADeprBook.SETFILTER("FA No.", FA."No.")) but that doesnt seem to do anything.

Header and the subform are linked by FA No.
I tried debugging it, and i found out that for some reason its not setting the FA No. in the subform (its always blank). But when I try using Ctrl+F8, i can see that is is set to the same FA No. as the header.

Any idea how I can do this??

Answers

  • ara3nara3n Member Posts: 9,256
    when there are more records to modify, you need to filter on the records.
    FA.GET("No.");
    FADeprBook.setrange("Fixed Assed No.",FA."No.");
    if FADeprBook.findset then repeat
      FADeprBook.validate("FA Posting Group" ,FA."FA Class Code");
      FADeprBook.MODIFY(true); 
    until FADeprBook.next = 0;
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • nvermanverma Member Posts: 396
    could you explain me the code you wrote....i sorta get it... what does the validate line do???
    FA.GET("No.");   // getting the FA No. 
    FADeprBook.setrange("Fixed Assed No.",FA."No."); // filtering on the fa depreciation book to get the same fa no as the header
    if FADeprBook.findset then repeat   // if the depreciation book exists
      FADeprBook.validate("FA Posting Group" ,FA."FA Class Code");   // ??????
      FADeprBook.MODIFY(true); // modifying the fa depreciation book
    until FADeprBook.next = 0; //untill there are no more fa deprecation books left in the subform.
    

    Also, there is only one issue with this code...lets say i set the FA class code to Building...it wouldnt show up in the fa posting group...but if i were to change the fa class code to something else....lets say Furniture...then the fa posting group would change to BUILDING. Its behind one for some reason if you know what i mean...
  • nvermanverma Member Posts: 396
    I had to modify the code to get it to update the values right away.
    FA.GET("No.");
    FADeprBook.SETRANGE("FA No.", FA."No.");
    IF FADeprBook.FINDSET THEN REPEAT
       FADeprBook."FA Posting Group" := Rec."FA Class Code";
       FADeprBook.MODIFY(TRUE);
    UNTIL FADeprBook.NEXT = 0;
    
  • ara3nara3n Member Posts: 9,256
    when you do assignment

    FADeprBook."FA Posting Group" := Rec."FA Class Code";


    you are not running the onvalidate trigger that is in the table. So if there was some code it would not run.


    When you call validate
    FADeprBook.validate("FA Posting Group" ,Rec."FA Class Code");



    if there was code onvalidate trigger in table it will execute the code. It is as though a user manually changing the field.

    If there is no code in the table in the trigger onvalidate then onvalidate is the same thing as assignment.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • SavatageSavatage Member Posts: 7,142
    nverma wrote:
    could you explain me the code you wrote....i sorta get it... what does the validate line ...
    I know we've discussed this before, but this is IMPORTANT stuff.
    Creating code or dataports or whatever in nav..you have to take into account all the other things going on behind the scenes. If there is code on the table behind that field your code won't execute it. therefore creating a future problem somewhere else. Just because it shows how you want in your current form doesn't mean it's correct everywhere in the system. and that's disaster down the road. be aware!
Sign In or Register to comment.