Can not get record from "Ship-to Address"

nikolainikolai Member Posts: 44
Hello, i want to get address from "Ship-to Address" table in invoice report. I defined global variable ShiptoAddress AS "Ship-to Address".

TransHeader - OnPreDataItem()
IF (TransHeader.GETFILTER("Transaction No.") = '') THEN
  CurrReport.QUIT;

TransHeader - OnAfterGetRecord()
FillPrintDoc();
PrintReports();

TransHeader - OnPostDataItem()

FillPrintDoc()
{IF (ExternalDocNo = '')
  OR (ShipmentDate = 0D)
  OR (ShippingAgentCode = '')
  OR (ShippingAgentServicesCode = '') THEN
  ERROR('Please fill all fields'); }

PrintDocHeader.INIT;
PrintDocLine.INIT;


//Get Retail Setup
IF (CurrStore.GET(TransHeader."Store No.")) THEN;

Customer.INIT;
IF (Customer.GET(TransHeader."Customer No.")) THEN;
BEGIN
  PrintDocHeader."Ship-to Address" := Customer.Address;
 [b] PrintDocHeader."Ship-to Address 2" :=
    ShiptoAddress.Address +' '+ShiptoAddress."Address 2" + ', ' + ShiptoAddress.City;[/b]
  PrintDocHeader."Ship-to Name" := Customer.Name;
  PrintDocHeader."Ship-to Phone" := ShiptoAddress."Phone No.";
END;


PrintDocHeader."Ship-to Address 2" :=
ShiptoAddress.Address +' '+ShiptoAddress."Address 2" + ', ' + ShiptoAddress.City;

is this wrong?
is any solution?

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Did you try
    FormatAddr.SalesInvShipTo(ShipToAddr,"Sales Invoice Header");
    

    Just check report 206 for more information
  • abhinav0408abhinav0408 Member Posts: 35
    you havn't specified a reference of PrintDocHeader table and ShipToAddress table.
    Use either setrange or Get function to create a refernce b/w two tables.
  • nikolainikolai Member Posts: 44
    I saw report 206, but i do not need to change it. i want to get "ShiptoAddress.Address" record for customer.
    Do i need to add something in my code for this?
  • nikolainikolai Member Posts: 44
    you havn't specified a reference of PrintDocHeader table and ShipToAddress table.
    Use either setrange or Get function to create a refernce b/w two tables.

    How can i do this?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    nikolai wrote:
    I saw report 206, but i do not need to change it. i want to get "ShiptoAddress.Address" record for customer.
    Do i need to add something in my code for this?

    I didnt tell you to change report 206 :wink:

    Copy the above code to your report and
    show ShipToAddr[1]..ShipToAddr[6] in your sections
  • nikolainikolai Member Posts: 44
    ok thank you i'll try and i'll post result :)
  • nikolainikolai Member Posts: 44
    Does it exists more easy way to do that? example to use get function?
    i can get customer address but shiptoadress not. how can i search ship to address
    if i know cutomer No?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    nikolai wrote:
    Does it exists more easy way to do that? example to use get function?
    i can get customer address but shiptoadress not. how can i search ship to address
    if i know cutomer No?

    ShiptoAddress.Get("Customer No.",InvHeader."Ship-to Address");
  • nikolainikolai Member Posts: 44
    I got error: "Unknown variable"

    here is code:
    Documentation()
    
    Report - OnInitReport()
    
    Report - OnPreReport()
    
    Report - OnPostReport()
    
    Report - OnCreateHyperlink(VAR URL : Text[1024])
    
    Report - OnHyperlink(URL : Text[1024])
    
    FillPrintDoc()
    {IF (ExternalDocNo = '')
      OR (ShipmentDate = 0D)
      OR (ShippingAgentCode = '')
      OR (ShippingAgentServicesCode = '') THEN
      ERROR('Please fill all fields'); }
    
    PrintDocHeader.INIT;
    PrintDocLine.INIT;
    
    
    //Get Retail Setup
    IF (CurrStore.GET(TransHeader."Store No.")) THEN;
    
    Customer.INIT;
    IF (Customer.GET(TransHeader."Customer No.")) THEN;
    //IF (ShiptoAddress.GET(TransHeader."Customer No.", TransHeader."Ship-to Code")) THEN;
    BEGIN
      PrintDocHeader."Ship-to Address" := Customer.Address;
      PrintDocHeader."Ship-to Address 2" :=
        ShiptoAddress.Address +' '+ShiptoAddress."Address 2" + ', ' + ShiptoAddress.City;
      PrintDocHeader."Ship-to Name" := Customer.Name;
      PrintDocHeader."Ship-to Phone" := ShiptoAddress."Phone No.";
    END;
    //ELSE
    {BEGIN
      PrintDocHeader."Ship-to Address" := Customer.Address;
      PrintDocHeader."Ship-to Address 2" :=
        Customer.Address +' '+ Customer."Address 2" + ', ' + ShiptoAddress.City;
      PrintDocHeader."Ship-to Name" := Customer.Name;
      PrintDocHeader."Ship-to Phone" := ShiptoAddress."Phone No.";
    END;}
    
    
    //EE
    IF ShiptoAddress.Address = '' THEN
       PrintDocHeader."Ship-to Address 2" := Customer.Address +' '+ Customer."Address 2" + ', ' + ShiptoAddress.City;
    
      PrintDocHeader."Ship-to Address 2" :=
        ShiptoAddress.Address +' '+ShiptoAddress."Address 2" + ', ' + ShiptoAddress.City;
    
    
    
    ShiptoAddress.Get("Customer No.",InvHeader."Ship-to Address");
    
    
    
    
    CompanyInfo.FIND('-');
    
    
    Counter := 1;
    
    PrintDocHeader."External Document No." := TransHeader."External Document No.";
    PrintDocHeader."Shipment Date" := TransHeader.Date;
    PrintDocHeader."Sell-to Customer No." := TransHeader."Customer No.";
    //PrintDocHeader."Shipping Agent Code" := TransHeader."Shipping Agent Code";
    PrintDocHeader."Stock Address" := CurrStore.Address + ', ' + CurrStore.City;
    PrintDocHeader."Shipping Agent Services Code" := ''; //TransHeader."Shipping Agent Service Code";
    PrintDocHeader."Zedd No." := TransHeader."Receipt No.";
    PrintDocHeader.Transfer := FALSE;
    PrintDocHeader."Stock Phone No." := CurrStore."Phone No.";
    PrintDocHeader."Ship-to VAT" := Customer."VAT Registration No.";
    
    
    PrintDocHeader.INSERT(TRUE);
    
    TransLine.RESET;
    TransLine.SETRANGE("Store No.", TransHeader."Store No.");
    TransLine.SETRANGE("POS Terminal No.", TransHeader."POS Terminal No.");
    TransLine.SETRANGE("Transaction No.", TransHeader."Transaction No.");
    IF (TransLine.FIND('-')) THEN
    REPEAT
    // IF (TransLine.Type=TransLine.Type::Item) THEN
     BEGIN
      SalesInvLine.RESET;
      SalesInvLine.SETRANGE("Document No.", SalesInvHeader."No.");
      SalesInvLine.SETRANGE("Line No.", TransLine."Line No.");
    
    
      PrintDocLine.INIT;
    
      PrintDocLine.Price := -(TransLine."Total Rounded Amt." - TransLine."VAT Amount");
      IF (TransLine.Quantity <> 0) THEN
        PrintDocLine."Unit Price" := -PrintDocLine.Price/TransLine.Quantity;
    
      PrintDocLine.VALIDATE("VAT Amount", -TransLine."VAT Amount");
      PrintDocLine."Line Amount" := -TransLine."Total Rounded Amt.";
    
      PrintDocLine."No." := FORMAT(Counter);
      PrintDocLine."Header No." := PrintDocHeader."No.";
      PrintDocLine.VALIDATE("Item No.", TransLine."Item No.");
      PrintDocLine.Quantity := -TransLine.Quantity;
      PrintDocLine."VAT Identifier" := '1';
      PrintDocLine."VAT Calculation Type" := PrintDocLine."VAT Calculation Type"::"Normal VAT";
      PrintDocLine."Tax Group Code" := '1';
      PrintDocLine."Amount Including VAT" := PrintDocLine."Line Amount";
      PrintDocLine."Inv. Discount Amount" := TransLine."Discount Amount";
      PrintDocLine."Allow Invoice Disc." := (TransLine."Discount Amount" <> 0);
    
      IF (PrintDocLine.Quantity <> 0) THEN
        PrintDocLine.INSERT;
      Counter := Counter + 1;
     END;
    UNTIL (TransLine.NEXT = 0);
    
    PrintReports()
    COMMIT;
    IF (Counter <> 1) THEN
    BEGIN
      PrintDocHeader.SETRANGE("No.", PrintDocHeader."No.");
      REPORT.RUNMODAL(50050,FALSE,FALSE,PrintDocHeader);  // UGT
    END;
    
    IF (PrintDocHeader.GET(PrintDocHeader."No.")) THEN
      PrintDocHeader.DELETE(TRUE);
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Tell us exactly what is your requirement?

    Try
    ShiptoAddress.Get("Customer No.",InvHeader."Ship-to Address");
    IF ShiptoAddress.Address = '' THEN
       PrintDocHeader."Ship-to Address 2" := Customer.Address +' '+ Customer."Address 2" + ', ' + ShiptoAddress.City
    ELSE
      PrintDocHeader."Ship-to Address 2" :=
        ShiptoAddress.Address +' '+ShiptoAddress."Address 2" + ', ' + ShiptoAddress.City;
    
  • nikolainikolai Member Posts: 44
    My target is to display ship-to address on report, but if it does not exist display customer address. customer address displays but ship to address not.
    after printing report "ship-to address".address is empty, but it exists for this custemer in ship-to address table.

    when i tried your code i got followning errors:
    Unknown varaiables Invheader And Customer No.


    Global variables: to view image click on it
    globalvars.png

    Uploaded with ImageShack.us

    Local variables:
    localvars.jpg

    Uploaded with ImageShack.us

    code:
    Documentation()
    
    TransHeader - OnPreDataItem()
    IF (TransHeader.GETFILTER("Transaction No.") = '') THEN
      CurrReport.QUIT;
    
    TransHeader - OnAfterGetRecord()
    FillPrintDoc();
    PrintReports();
    
    TransHeader - OnPostDataItem()
    
    FillPrintDoc()
    {IF (ExternalDocNo = '')
      OR (ShipmentDate = 0D)
      OR (ShippingAgentCode = '')
      OR (ShippingAgentServicesCode = '') THEN
      ERROR('Please fill all fields'); }
    
    PrintDocHeader.INIT;
    PrintDocLine.INIT;
    
    
    //Get Retail Setup
    IF (CurrStore.GET(TransHeader."Store No.")) THEN;
    
    Customer.INIT;
    IF (Customer.GET(TransHeader."Customer No.")) THEN;
    //IF (ShiptoAddress.GET(TransHeader."Customer No.", TransHeader."Ship-to Code")) THEN;
    BEGIN
      PrintDocHeader."Ship-to Address" := Customer.Address;
      PrintDocHeader."Ship-to Address 2" :=
        ShiptoAddress.Address +' '+ShiptoAddress."Address 2" + ', ' + ShiptoAddress.City;
      PrintDocHeader."Ship-to Name" := Customer.Name;
      PrintDocHeader."Ship-to Phone" := ShiptoAddress."Phone No.";
    END;
    //ELSE
    {BEGIN
      PrintDocHeader."Ship-to Address" := Customer.Address;
      PrintDocHeader."Ship-to Address 2" :=
        Customer.Address +' '+ Customer."Address 2" + ', ' + ShiptoAddress.City;
      PrintDocHeader."Ship-to Name" := Customer.Name;
      PrintDocHeader."Ship-to Phone" := ShiptoAddress."Phone No.";
    END;}
    
    
    //EE
    IF ShiptoAddress.Address = '' THEN
       PrintDocHeader."Ship-to Address 2" := Customer.Address +' '+ Customer."Address 2" + ', ' + ShiptoAddress.City;
    
    
    
    
    CompanyInfo.FIND('-');
    
    
    Counter := 1;
    
    PrintDocHeader."External Document No." := TransHeader."External Document No.";
    PrintDocHeader."Shipment Date" := TransHeader.Date;
    PrintDocHeader."Sell-to Customer No." := TransHeader."Customer No.";
    //PrintDocHeader."Shipping Agent Code" := TransHeader."Shipping Agent Code";
    PrintDocHeader."Stock Address" := CurrStore.Address + ', ' + CurrStore.City;
    PrintDocHeader."Shipping Agent Services Code" := ''; //TransHeader."Shipping Agent Service Code";
    PrintDocHeader."Zedd No." := TransHeader."Receipt No.";
    PrintDocHeader.Transfer := FALSE;
    PrintDocHeader."Stock Phone No." := CurrStore."Phone No.";
    PrintDocHeader."Ship-to VAT" := Customer."VAT Registration No.";
    PrintDocHeader.INSERT(TRUE);
    
    TransLine.RESET;
    TransLine.SETRANGE("Store No.", TransHeader."Store No.");
    TransLine.SETRANGE("POS Terminal No.", TransHeader."POS Terminal No.");
    TransLine.SETRANGE("Transaction No.", TransHeader."Transaction No.");
    IF (TransLine.FIND('-')) THEN
    REPEAT
    // IF (TransLine.Type=TransLine.Type::Item) THEN
     BEGIN
      SalesInvLine.RESET;
      SalesInvLine.SETRANGE("Document No.", SalesInvHeader."No.");
      SalesInvLine.SETRANGE("Line No.", TransLine."Line No.");
    
    
      PrintDocLine.INIT;
    
      PrintDocLine.Price := -(TransLine."Total Rounded Amt." - TransLine."VAT Amount");
      IF (TransLine.Quantity <> 0) THEN
        PrintDocLine."Unit Price" := -PrintDocLine.Price/TransLine.Quantity;
    
      PrintDocLine.VALIDATE("VAT Amount", -TransLine."VAT Amount");
      PrintDocLine."Line Amount" := -TransLine."Total Rounded Amt.";
    
      PrintDocLine."No." := FORMAT(Counter);
      PrintDocLine."Header No." := PrintDocHeader."No.";
      PrintDocLine.VALIDATE("Item No.", TransLine."Item No.");
      PrintDocLine.Quantity := -TransLine.Quantity;
      PrintDocLine."VAT Identifier" := '1';
      PrintDocLine."VAT Calculation Type" := PrintDocLine."VAT Calculation Type"::"Normal VAT";
      PrintDocLine."Tax Group Code" := '1';
      PrintDocLine."Amount Including VAT" := PrintDocLine."Line Amount";
      PrintDocLine."Inv. Discount Amount" := TransLine."Discount Amount";
      PrintDocLine."Allow Invoice Disc." := (TransLine."Discount Amount" <> 0);
    
      IF (PrintDocLine.Quantity <> 0) THEN
        PrintDocLine.INSERT;
      Counter := Counter + 1;
     END;
    UNTIL (TransLine.NEXT = 0);
    
    PrintReports()
    COMMIT;
    IF (Counter <> 1) THEN
    BEGIN
      PrintDocHeader.SETRANGE("No.", PrintDocHeader."No.");
      REPORT.RUNMODAL(50050,FALSE,FALSE,PrintDocHeader);  // UGT
    END;
    
    IF (PrintDocHeader.GET(PrintDocHeader."No.")) THEN
      PrintDocHeader.DELETE(TRUE);
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    replace
    IF ShiptoAddress.Address = '' THEN
       PrintDocHeader."Ship-to Address 2" := Customer.Address +' '+ Customer."Address 2" + ', ' + ShiptoAddress.City;
    

    with
    IF ShiptoAddress.GET(TransHeader."Customer No.", TransHeader."Ship-to Code") THEN BEGIN
      IF ShiptoAddress.Address = '' THEN
        PrintDocHeader."Ship-to Address 2" := Customer.Address +' '+ Customer."Address 2" + ', ' + ShiptoAddress.City
      ELSE
        PrintDocHeader."Ship-to Address 2" :=
          ShiptoAddress.Address +' '+ShiptoAddress."Address 2" + ', ' + ShiptoAddress.City;
    END;
    
  • nikolainikolai Member Posts: 44
    got error:
    "you have specified an inknown variable.
    Ship-to Code

    Define the variable under 'Global C/AL symbols'.

    "
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    nikolai wrote:
    got error:
    "you have specified an inknown variable.
    Ship-to Code

    Define the variable under 'Global C/AL symbols'.

    "

    Which table is TransHeader?

    BTW, Are you technical consultant? :-k
  • nikolainikolai Member Posts: 44
    nikolai wrote:
    got error:
    "you have specified an inknown variable.
    Ship-to Code

    Define the variable under 'Global C/AL symbols'.

    "

    Which table is TransHeader?

    BTW, Are you technical consultant? :-k

    "Transaction Header ", yes i am begginer :)
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    In Sales Header, we have Ship-to Code to give Shipment address
    In Transfer Header, we dont have any field with Ship-to Code..
    Then from where you want to get the Ship-to Code?
  • nikolainikolai Member Posts: 44
    In Sales Header, we have Ship-to Code to give Shipment address
    In Transfer Header, we dont have any field with Ship-to Code..
    Then from where you want to get the Ship-to Code?


    I whant to get address from "ship-to address" table, not ship to code.
    address is in "Ship-to Address" table.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    nikolai wrote:
    I whant to get address from "ship-to address" table, not ship to code.
    address is in "Ship-to Address" table.

    we will have 100 records in "ship-to address" table
    out of 100, which record you want?
  • nikolainikolai Member Posts: 44
    nikolai wrote:
    I whant to get address from "ship-to address" table, not ship to code.
    address is in "Ship-to Address" table.

    we will have 100 records in "ship-to address" table
    out of 100, which record you want?

    Where TransHeader."Customer No."="Ship-to Address"."Customer No."
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    nikolai wrote:
    nikolai wrote:
    I whant to get address from "ship-to address" table, not ship to code.
    address is in "Ship-to Address" table.

    we will have 100 records in "ship-to address" table
    out of 100, which record you want?

    Where TransHeader."Customer No."="Ship-to Address"."Customer No."

    Again you may have 100 records with (TransHeader."Customer No."="Ship-to Address"."Customer No.") this combination.
    as primary key is Customer No.,Code

    Now???
  • nikolainikolai Member Posts: 44
    edited 2011-03-22
    ok i understand. "Transaction header"."Ship-to Address" is code in my case

    Where TransHeader."Customer No."="Ship-to Address"."Customer No." AND
    TransHeader."Ship-to Adress"="Ship-to Address".code

    it seems that in "Ship-to Address" table there is no two same customer's address.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    nikolai wrote:
    ok i understand. "Transaction header"."Ship-to Address" is code in my case

    Where TransHeader."Customer No."="Ship-to Address"."Customer No." AND
    TransHeader."Ship-to Adress"="Ship-to Address".code

    Is "Transaction header"."Ship-to Address" customized field?
    If yes,

    replace
    IF ShiptoAddress.GET(TransHeader."Customer No.", TransHeader."Ship-to Code") THEN BEGIN
    
    with
    IF ShiptoAddress.GET(TransHeader."Customer No.", TransHeader."Ship-to Address") THEN BEGIN
    
    in my above code
  • vijay_gvijay_g Member Posts: 884
    you need to create a field "ship to code" in transaction header and then assign it to a code for a perticular customer exist in transaction header as working in sales header.

    because without adding or linking "ship to code" from ship-to-address table you can't get all detail.
    based on this field check how's rest of the fields populating in sales header.
  • vijay_gvijay_g Member Posts: 884
    ok then use ship-to-address field to as a ship-to-code.
  • nikolainikolai Member Posts: 44
    Thank you it works now :)
Sign In or Register to comment.