RSS

How to update/edit customer addresses with additional address purposes?

25 Mar

Requirements:  Needs to update all customer addresses with a delivery purpose to also have an invoice purpose.

image

image

Solution:
This job below will update every customer’s address which has purpose Delivery with additional Invoice purpose. We can extent this to update/edit vendor address as well.

static void updateCustomerPostalAddresses(Args _args)
{
    #define.Delivery("Delivery")
    CustTable custTable;
    DirPartyPostalAddressView   addressView;
    LogisticsPostalAddress      postalAddress;
    DirPartyLocationEntity      partyLocationEntity;
    container purposes;
    int counter;
    
    ttsBegin;
    setPrefix("Update Customer addresses:");
    // Iterate every customer    
    while select * from custTable        
    {
        setPrefix(strFmt("Customer: %1", custTable.AccountNum));
        {
            // Iterate every addresses every customer has
            while select addressView
                where addressView.Party == custTable.Party
            {
                if(strScan(addressView.locationRoles(), #Delivery, 1, strLen(addressView.locationRoles())))
                {
                    if (DirPartyLocation::findByPartyLocation(addressView.Party, addressView.Location))
                    {
                        postalAddress = LogisticsPostalAddress::findByLocation(addressView.Location, true);
                        if (postalAddress.RecId > 0)
                        {
                            partyLocationEntity = DirPartyLocationEntity::construct(addressView.Party);
                            partyLocationEntity.parmLocation(postalAddress.Location);
                        
                            purposes = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
                                                
                            // Create party links
                            partyLocationEntity.createPartyLocationAssociation(purposes, addressView.IsPrimary, addressView.IsPrivate);
                            info(strFmt("Update address: %1",  addressView.Address));
                            counter++;
                        }
                    }                
                }
            }
        }            
    }
    
    info(strFmt("Total address(es) updated: %1", counter));
    ttsCommit;
}

Result:

image

image

Advertisements
 
Leave a comment

Posted by on March 25, 2014 in Development

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: