Saturday, January 4, 2014

Create warehouse addresses through code in Ax 2012

Hi guys, 

Below code can be used to create warehouse addresses in Ax 2012.

   InventLocation                           warehouse;
    LogisticsPostalAddressView      postalAddressView;
    LogisticsPostalAddress              postalAddress;
    LogisticsEntityLocationMap       locationMap;
    container                                   role, roleMap;
    Map                                         LocationRoleMap;
    LogisticsPostalAddressEntity    postalAddressEntity  = new LogisticsPostalAddressEntity();
    ;

    warehouse                                            = InventLocation::find('CR004');

    postalAddressView.Street                    = 'Test street222';
    postalAddressView.City                       = 'Tcity';
    postalAddressView.State                     = '';
    postalAddressView.ZipCode               = '622001';
    postalAddressView.CountryRegionId   = 'SASCO';
    postalAddressView.LocationName       = 'TDlvAddr';

    postalAddress        = postalAddressEntity.createPostalAddress(postalAddressView);
    locationMap           = LogisticsEntityLocationMap::find(tableNum(InventLocationLogisticsLocation), warehouse.RecId, postalAddress.Location);

    locationMap.Entity                      = warehouse.RecId;
    locationMap.Location                 = postalAddress.Location;
    locationMap.IsPostalAddress     = NoYes::Yes;
    locationMap.IsPrimary               = NoYes::Yes;
    locationMap.IsPrivate                = NoYes::No;

    LocationRoleMap       = LogisticsLocationEntity::getDefaultLocationRoleFromEntity(tableName2id("InventLocation"));

    roleMap                     = map2Con(LocationRoleMap);
    role                            = conpeek(roleMap, 1);

    locationMap.addEntityLocation(role ,true);

1 comment:

  1. Thank you very much for the information provided! I was looking for this data for a long time, but I was not able to find the trusted source..
    change my address

    ReplyDelete