XMLport send Post Code plus Ship-to Adress

RikarddoRikarddo Member Posts: 66
Hello all,

I'm building a XMLport that sends some information to our internal sofwtare, such as name of contact, address , post code etc..im getting difficulties on the post code.

The logic is, if the the contact is customer, then it returns by default the customer post code. If that customer has more than shipping address than it returns the customer post code and those shipping post codes.

If the contact is not customer it returns the contact post code.


Node Name Prefix Node Type Source Type Data Source
XMLPesquisaContacto Element Text <XMLPesquisaContacto>

ContactoNo Element Text <ContactoNo>
Contacto Element Table <Contact>(Contact)
No Element Field Contact::No.
CodPostal Element Field Contact::Post Code
CodPais Element Text <CodPais>
PaymtTerms Element Table <Payment Terms>(Payment Terms)
CodTerms Element Field Payment Terms::Code
Descricao Element Field Payment Terms::Description
Ship-toAddress Element Table <Ship-to Address>(Ship-to Address)
CodPostalEndEnv Element Text <CodPostalEndEnv>


This is for now the code i have

//{código original

CLEARALL();
 CodPais:='';
 ltBusRel.RESET;
 ltBusRel.SETRANGE("Contact No.",ContactoNo);
 ltBusRel.SETRANGE("Business Relation Code",'CLI');
 IF ltBusRel.FINDFIRST THEN BEGIN
  Contact.RESET;
  Contact.SETRANGE("No.",ltBusRel."Contact No.");
  IF Contact.FIND('-') THEN
     IF Contact."Country/Region Code"<> '' THEN BEGIN
      CodPais:=Contact."Country/Region Code";
      CodPostalEndEnv:=Contact."Post Code";
      pesquisacontacto.SETTABLEVIEW(Contact);

     END
     ELSE BEGIN
     CodPais:='PT';
     pesquisacontacto.SETTABLEVIEW(Contact);
     END;
 END;
//}

This is the code i'm trying to implement
{
CLEARALL();
CodPostalEndEnv:=Contact."Post Code"; 
ltBusRel.RESET;
ltBusRel.SETRANGE("Contact No.",ContactoNo);
ltBusRel.SETRANGE("Business Relation Code",'CLI');
IF ltBusRel.FINDFIRST THEN 
BEGIN
  ltcustomer.RESET;
  ltcustomer.SETRANGE("No.",ltBusRel."No.");
  IF ltcustomer.FIND('-') THEN 
  BEGIN
    "Ship-to Address".RESET;
    "Ship-to Address".SETRANGE("Customer No.",ltBusRel."No.");
    IF "Ship-to Address".FIND('-') THEN 
    BEGIN
      REPEAT
      CodPostalEndEnv:="Ship-to Address"."Post Code";
      pesquisacontacto.SETTABLEVIEW("Ship-to Address");
      UNTIL "Ship-to Address".NEXT=0;
    END
    ELSE BEGIN
    CodPostalEndEnv:=Contact."Post Code";
    pesquisacontacto.SETTABLEVIEW(Contact);
    END;
  END;
END
ELSE
BEGIN
  ltBusRel.RESET;
  ltBusRel.SETRANGE("Contact No.",ContactoNo);
  IF ltBusRel.FINDFIRST THEN
  BEGIN
    CodPostalEndEnv:=Contact."Post Code";
    pesquisacontacto.SETTABLEVIEW(Contact);
  END;
END;

But 'ive got errors if customer has only post code. If customer has shipping addresses then it return the first post code only repeatd n times.

I've managed to got working to payment terms.
Payment Terms - Export::OnPreXMLItem()
 CLEARALL();
 CodPais:='';
 ltBusRel.RESET;
 ltBusRel.SETRANGE("Contact No.",ContactoNo);
 ltBusRel.SETRANGE("Business Relation Code",'CLI');
  IF ltBusRel.FINDFIRST THEN BEGIN
  Contact.RESET;
  Contact.SETRANGE("No.",ltBusRel."Contact No.");
  IF Contact.FIND('-') THEN
     IF Contact."Country/Region Code"<> '' THEN
        CodPais:=Contact."Country/Region Code"      
     ELSE BEGIN
        CodPais:='PT';
        pesquisacontacto.SETTABLEVIEW(Contact);
     END;
  ltcustomer.RESET;
  ltcustomer.SETRANGE("No.",ltBusRel."No.");
  IF ltcustomer.FIND('-') THEN BEGIN
    "Payment Terms".RESET;
    "Payment Terms".SETCURRENTKEY(Code);
    "Payment Terms".ASCENDING(FALSE);
    "Payment Terms".SETFILTER(Code,'%1|%2',ltcustomer."Payment Terms Code",'A');
      IF "Payment Terms".FIND('-') THEN BEGIN
        pesquisacontacto.SETTABLEVIEW("Payment Terms");
      END;
  END
  ELSE 
  BEGIN
      CodPais:='PT';
      "Payment Terms".RESET;
      "Payment Terms".SETFILTER(Code,'%1','A');
      pesquisacontacto.SETTABLEVIEW("Payment Terms");
END;
END;

Any help would be appreciated .

Best Answer

  • RikarddoRikarddo Member Posts: 66
    Accepted Answer
    If someone someday has the same problem, here it is the solution:

    Node Name Prefix Node Type Source Type Data Source
    XMLPesquisaContacto Element Text <XMLPesquisaContacto>

    ContactoNo Element Text <ContactoNo>
    Contacto Element Table <Contact>(Contact)
    No Element Field Contact::No.
    CodPostal Element Field Contact::Post Code
    CodPais Element Text <CodPais>
    PaymtTerms Element Table <Payment Terms>(Payment Terms)
    CodTerms Element Field Payment Terms::Code
    Descricao Element Field Payment Terms::Description
    Ship-toAddress Element Table <Ship-to Address>(Ship-to Address)
    CodPostalEndEnv Element Text <CodPostalEndEnv>

    Tip: Ship-toAddress temporary



    Contact - Export::OnPreXMLItem()
     CLEARALL();
     CodPais:='';
     ltBusRel.RESET;
     ltBusRel.SETRANGE("Contact No.",ContactoNo);
     ltBusRel.SETRANGE("Business Relation Code",'CLI');
     IF ltBusRel.FINDFIRST THEN 
     BEGIN
      Contact.RESET;
      Contact.SETRANGE("No.",ltBusRel."Contact No.");
      IF Contact.FIND('-') THEN
         IF Contact."Country/Region Code"<> '' THEN
            CodPais:=Contact."Country/Region Code"      
         ELSE 
         BEGIN
            CodPais:='PT';
            pesquisacontacto.SETTABLEVIEW(Contact);
         END;
      ltcustomer.RESET;
      ltcustomer.SETRANGE("No.",ltBusRel."No.");
      IF ltcustomer.FIND('-') THEN 
      BEGIN
      "Ship-to Address"."Post Code":=ltcustomer."Post Code";
      "Ship-to Address".INSERT;
        ShiptoAddress.RESET;
        ShiptoAddress.SETRANGE("Customer No.",ltcustomer."No.");
        ShiptoAddress.SETCURRENTKEY("Customer No.",Code);
        IF ShiptoAddress.FINDFIRST THEN 
        BEGIN 
        IF ShiptoAddress.Code<>'' THEN BEGIN
          REPEAT
            "Ship-to Address":=ShiptoAddress;
            "Ship-to Address".INSERT;
          UNTIL ShiptoAddress.NEXT=0;
         
        END;
        END
        ELSE
        BEGIN
          "Ship-to Address"."Post Code":=Contact."Post Code";
          "Ship-to Address".MODIFY;
        END;
    
      END;
    END
    
    ELSE 
    BEGIN
    Contact.RESET;
    Contact.SETRANGE("No.",ContactoNo);
     IF Contact.FIND('-') THEN BEGIN
         CodPais:='PT';
         "Ship-to Address"."Post Code":=Contact."Post Code";
         "Ship-to Address".INSERT;
         pesquisacontacto.SETTABLEVIEW(Contact);
     END;
    END;
    

Answers

  • RikarddoRikarddo Member Posts: 66
    Accepted Answer
    If someone someday has the same problem, here it is the solution:

    Node Name Prefix Node Type Source Type Data Source
    XMLPesquisaContacto Element Text <XMLPesquisaContacto>

    ContactoNo Element Text <ContactoNo>
    Contacto Element Table <Contact>(Contact)
    No Element Field Contact::No.
    CodPostal Element Field Contact::Post Code
    CodPais Element Text <CodPais>
    PaymtTerms Element Table <Payment Terms>(Payment Terms)
    CodTerms Element Field Payment Terms::Code
    Descricao Element Field Payment Terms::Description
    Ship-toAddress Element Table <Ship-to Address>(Ship-to Address)
    CodPostalEndEnv Element Text <CodPostalEndEnv>

    Tip: Ship-toAddress temporary



    Contact - Export::OnPreXMLItem()
     CLEARALL();
     CodPais:='';
     ltBusRel.RESET;
     ltBusRel.SETRANGE("Contact No.",ContactoNo);
     ltBusRel.SETRANGE("Business Relation Code",'CLI');
     IF ltBusRel.FINDFIRST THEN 
     BEGIN
      Contact.RESET;
      Contact.SETRANGE("No.",ltBusRel."Contact No.");
      IF Contact.FIND('-') THEN
         IF Contact."Country/Region Code"<> '' THEN
            CodPais:=Contact."Country/Region Code"      
         ELSE 
         BEGIN
            CodPais:='PT';
            pesquisacontacto.SETTABLEVIEW(Contact);
         END;
      ltcustomer.RESET;
      ltcustomer.SETRANGE("No.",ltBusRel."No.");
      IF ltcustomer.FIND('-') THEN 
      BEGIN
      "Ship-to Address"."Post Code":=ltcustomer."Post Code";
      "Ship-to Address".INSERT;
        ShiptoAddress.RESET;
        ShiptoAddress.SETRANGE("Customer No.",ltcustomer."No.");
        ShiptoAddress.SETCURRENTKEY("Customer No.",Code);
        IF ShiptoAddress.FINDFIRST THEN 
        BEGIN 
        IF ShiptoAddress.Code<>'' THEN BEGIN
          REPEAT
            "Ship-to Address":=ShiptoAddress;
            "Ship-to Address".INSERT;
          UNTIL ShiptoAddress.NEXT=0;
         
        END;
        END
        ELSE
        BEGIN
          "Ship-to Address"."Post Code":=Contact."Post Code";
          "Ship-to Address".MODIFY;
        END;
    
      END;
    END
    
    ELSE 
    BEGIN
    Contact.RESET;
    Contact.SETRANGE("No.",ContactoNo);
     IF Contact.FIND('-') THEN BEGIN
         CodPais:='PT';
         "Ship-to Address"."Post Code":=Contact."Post Code";
         "Ship-to Address".INSERT;
         pesquisacontacto.SETTABLEVIEW(Contact);
     END;
    END;
    
Sign In or Register to comment.