Pages

Showing posts with label address. Show all posts
Showing posts with label address. Show all posts

Sunday, March 6, 2011

How to iterate over addresses in the global address book of Vendors/Customers

I'm frequently asked to mass update addresses for vendors or customers during data imports when something isn't imported correctly.  Here is a simple job that I wrote that shows the relationship between the tables, that you can modify to fit your needs.



static void iterateOverAddresses(Args _args)
{
    VendTable                           vendTable;
    Address                             address;
    DirPartyAddressRelationship         dpar;
    DirPartyAddressRelationshipMapping  dparm;
    ;

    while select address
        join dpar
        join dparm
        join vendTable
        where
              vendTable.PartyId         == dpar.PartyId                         &&
              dpar.RecId                == dparm.PartyAddressRelationshipRecId  &&
              dparm.RefCompanyId        == curExt()                             &&
              dparm.AddressRecId        == address.RecId
    {
        info(address.Name);
    }
}

Wednesday, February 16, 2011

Fixing addresses that are not formatted correctly

An issue that comes up often at various clients is addresses being formatted incorrectly.  Functional people have been able to fix this by "touching" the zip code on the address with an issue...basically they click on it and re-choose the zip code and save to fix it.

What is going on behind the scenes, is the AddressMap is being used to correctly format the address.

The Address.address, CustTable.address, VendTable.address, etc. fields should not be manually filled in.  They should not have data dumped into them either.  It is a derived/built field that depends on the country code and each individual format.

This is important when you deal with international customers and customs.  Customs for European countries, for example, can be very picky with documents.  If the address is even slightly malformed, I've seen product get held for up to a month, and sometimes it's seized...all for a silly address error.

Here is a job I wrote that can be adapted to automate the process of building addresses using AddressMap.  Right now, it lets you pick a customer that you want to correct the addresses for, then displays a before/after of the addresses.

Enjoy!  As always, comments are welcome!



static void updateCustAddress(Args _args)
{
    Dialog                              dialog;
    DialogField                         field;
    CustTable                           custTable;
    Address                             address;
    DirPartyAddressRelationship         dpar;
    DirPartyAddressRelationshipMapping  dparm;
    AccountNum                          accountNum;
    ;

    dialog  = new Dialog("Build customer address");
    dialog.addText("Select your customer to update:");
    field   = dialog.addField(typeid(CustAccount));
    dialog.run();

    if(dialog.closedOk())
    {
        accountNum = field.value();

        if (CustTable::exist(accountNum))
        {
            ttsbegin;
            while select forupdate address
                join dpar
                join dparm
                join custTable
                where custTable.AccountNum      == accountNum          &&
                      custTable.PartyId         == dpar.PartyId         &&
                      dpar.RecId                == dparm.PartyAddressRelationshipRecId  &&
                      dparm.RefCompanyId        == curExt()               &&
                      dparm.AddressRecId        == address.RecId
            {
                info(strfmt("Type %1 - before:", address.type));
                info(strFmt(">%1<", address.Address));
                
                address.AddressMap::setAddress();
                address.update();
                
                info(strfmt("Type %1 - after:", address.type));
                info(strFmt("<%1>", address.Address));
            }
            ttscommit;
        }
        else
        {
            info("Invalid Account");
        }

    }

    info("Done");
}