How to Copy Contact Address to Bill-to Address

knmknm Member Posts: 170
Hi,

I was trying to find out how I can manage to copy the Contact Address details (Address1, Address2, etc) to Bill-to Address details on Sales Order.

Since when Contact No. is modified on the SO, the "Bill-to Name" changes using the Contact Name assigned on the Contact No, I thought that it should be very easy copying all other information by adding extra codes next to the copy function in "Contact".

But as I was reviewing the NAV 2009 SP1 codes, I couldn't find the code that was handling the copy function.

Maybe I'm not looking at the right place...
If you could point me to the right direction as to where to look for the codes, and how to update it, I would greatly appreciate it.

Thank you.

Kenji

Comments

  • AndwianAndwian Member Posts: 627
    NAV 5 SP1 ID:

    Bill-to Contact No. - OnValidate()
    .....
    UpdateBillToCust("Bill-to Contact No.");
    
    Regards,
    Andwian
  • rsaritzkyrsaritzky Member Posts: 469
    To add some info to Andwian's reply, the code that he noted is the last line of the
    "Bill-To Contact No." ONVALIDATE trigger (as he mentioned). The "UpdateBillToCust" function's code is here:
    IF Cont.GET(ContactNo) THEN BEGIN
      "Bill-to Contact No." := Cont."No.";
      IF Cont.Type = Cont.Type::Person THEN
        "Bill-to Contact" := Cont.Name
      ELSE
        IF Cust.GET("Bill-to Customer No.") THEN
          "Bill-to Contact" := Cust.Contact
        ELSE
          "Bill-to Contact" := '';
    END ELSE BEGIN
      "Bill-to Contact" := '';
      EXIT;
    END;
    
    ContBusinessRelation.RESET;
    ContBusinessRelation.SETCURRENTKEY("Link to Table","Contact No.");
    ContBusinessRelation.SETRANGE("Link to Table",ContBusinessRelation."Link to Table"::Customer);
    ContBusinessRelation.SETRANGE("Contact No.",Cont."Company No.");
    IF ContBusinessRelation.FINDFIRST THEN BEGIN
      IF "Bill-to Customer No." = '' THEN BEGIN
        SkipBillToContact := TRUE;
        VALIDATE("Bill-to Customer No.",ContBusinessRelation."No.");
        SkipBillToContact := FALSE;
        "Bill-to Customer Template Code" := '';
      END ELSE
        IF "Bill-to Customer No." <> ContBusinessRelation."No." THEN
          ERROR(Text037,Cont."No.",Cont.Name,"Bill-to Customer No.");
    END ELSE BEGIN
      IF "Document Type" = "Document Type"::Quote THEN BEGIN
        Cont.TESTFIELD("Company No.");
        ContComp.GET(Cont."Company No.");
        "Bill-to Name" := ContComp."Company Name";
        "Bill-to Name 2" := ContComp."Name 2";
        "Bill-to Address" := ContComp.Address;
        "Bill-to Address 2" := ContComp."Address 2";
        "Bill-to City" := ContComp.City;
        "Bill-to Post Code" := ContComp."Post Code";
        "Bill-to County" := ContComp.County;
        "Bill-to Country/Region Code" := ContComp."Country/Region Code";
        "VAT Registration No." := ContComp."VAT Registration No.";
        VALIDATE("Currency Code",ContComp."Currency Code");
        "Language Code" := ContComp."Language Code";
        IF ("Bill-to Customer Template Code" = '') AND (NOT CustTemplate.ISEMPTY) THEN
          VALIDATE("Bill-to Customer Template Code",Cont.FindCustomerTemplate);
      END ELSE
        ERROR(Text039,Cont."No.",Cont.Name);
    END;
    

    You can see that it would be relatively easy to copy the Contact Address details to the Bill-to address details on the order - in fact, it is already done when the order is type "Quote". So you could change one line of code above from
    IF "Document Type" = "Document Type"::Quote THEN BEGIN
    
    to
    IF ("Document Type" = "Document Type"::Quote) OR ("Document Type" = "Document Type"::Order) THEN BEGIN
    

    I'm not sure that's the exact functionality you are looking for, but hopefully it will point you in the right direction.
    Ron
Sign In or Register to comment.