Copy a field to the same field on another table

DarkHorseDarkHorse Member Posts: 389
Hello, I've the field "Credit Limit (LCY)" -decimal type-on Customer and Contact table. On Contact table, on Credit Limit onValidate trigger, I've the code:
recContBusinRel.RESET ;
recContBusinRel.SETRANGE("Contact No.", "No.") ;
recContBusinRel.SETRANGE("Link to Table", recContBusinRel."Link to Table"::Customer) ;
IF recContBusinRel.FIND('-') THEN BEGIN
   Cust.RESET ;
 IF Cust.GET(recContBusinRel."No.") THEN BEGIN
      Cust."Credit Limit (LCY)" := "Credit Limit (LCY)" ;
      Cust.MODIFY ;
   END ;
END ;

recContBusinRel is Contact Bussiness Relation table
Cust is Customer table

The code copy the Credit limit field from contact table to credit limit field customer table when you go from contact tab to customer tab.
But it doesn't work on reserve, i mean, I modify the credit limit field on customer tab but it doesn't copy to credit limit contact table field. I've put the same code (changing tables obviosly) on onvalidate trigger from credit limit field on customer table, but it doesn't work. Does anybody knows what can be the problem?.
Thanks in advance.

Comments

  • garakgarak Member Posts: 3,263
    From Contact -> Customer:
    Credit Limit (LCY) - OnValidate()
    
    //A Creditlimit is only possible if it is the Company and not a person
    ContBusRel.RESET;
    ContBusRel.SETRANGE("Contact No.","Company No.");
    ContBusRel.SETFILTER("No.",'<>''''');
    ContBusRel.SETRANGE("Link to Table",ContBusRel."Link to Table"::Customer);
    IF ContBusRel.FINDFIRST THEN BEGIN
      Cust.GET(ContBusRel."No.");
      Cust."Credit Limit (LCY)" := "Credit Limit (LCY)";
      Cust.MODIFY;
    END;
    

    From Customer -> Contact:
    ContBusRel.SETCURRENTKEY("Link to Table","No.");
    ContBusRel.SETRANGE("Link to Table",ContBusRel."Link to Table"::Customer);
    ContBusRel.SETRANGE("No.","No.");
    if ContBusRel.findfirst then begin
      Contact.get(ContBusRel."Contact No.");
      Contact."Credit Limit (LCY)" := "Credit Limit (LCY)";
      Contact.MODIFY;
    end;
    

    BUT better is, if you take a look into the Codeunit "CustCont-Update" from
    Customer - OnModify Trigger
    UpdateContFromCust.OnModify(Rec)
    

    and into the Codeunit "CustVendBank-Update" from
    Contact - OnModify(xRec : Record Contact) FUNCTION
    

    The codesnippes above from me was only an example (but it work, better use the 2 codeunits that i post).

    Regards
    Do you make it right, it works too!
  • DaveTDaveT Member Posts: 1,039
    Hi,

    Can you post the reverse code - there may be a confusion with "No." vs "Contact No."
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • garakgarak Member Posts: 3,263
    @DaveT: Do you mean me?
    Do you make it right, it works too!
  • DaveTDaveT Member Posts: 1,039
    Hi Garak,

    No - I must be a slow typer as you posted all the code in the time it took me to post a single line of text :mrgreen:

    Must get out of the habit of leaving multiple tabs open :oops:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • garakgarak Member Posts: 3,263
    DaveT wrote:
    Must get out of the habit of leaving multiple tabs open :oops:

    I use also more then one tab, but it's not the tab problem, it's your speed ;-) :oops:
    Do you make it right, it works too!
  • DaveTDaveT Member Posts: 1,039
    :mrgreen: Like my teacher used to say "must try harder" :mrgreen:
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • garakgarak Member Posts: 3,263
    DaveT wrote:
    :mrgreen: Like my teacher used to say "must try harder" :mrgreen:

    Oh, you had the same teachers as I (Mr. Smith, my old Englishman, english teacher) :roll: :roll:
    Do you make it right, it works too!
  • DarkHorseDarkHorse Member Posts: 389
    Thanks both for help; it works perfectly!!!.
    Thanks again.
Sign In or Register to comment.