Skip to main content

Convert Dynamics AX Entity Private Address into Public GAB Address

In this article, we will see how to convert Customer / Vendor's private addresses into public GAB addresses. If you try to do it manually by clicking the public check box on a private address then it will just not allow you to do it.

Here is the code to do so:

   1:  //Converts private addresses to public addresses
   2:  static void ConvertPrivateAddressToPublic(Args _args)
   3:  {
   4:      #OCCRetryCount
   5:      DirPartyAddressRelationshipMapping  dirPartyAddressRelationshipMapping;
   6:      Address                             address, address2;
   7:      DirParty                            dirParty;
   8:      DirPartyTable                       dirPartyTable;
   9:   
  10:      void convertAddress()
  11:      {
  12:          ;
  13:          address.clear();
  14:          address = Address::findRecId(address2.RecId, true);
  15:   
  16:          //dir party associated with the entity
  17:          dirParty = DirParty::constructFromCommon(address);
  18:   
  19:          dirPartyTable = DirPartyTable::find(dirParty.parmPartyId());
  20:   
  21:          //update these values so that this private address now belongs to the party of the entity
  22:          address.AddrTableId = dirPartyTable.TableId;
  23:          address.AddrRecId   = dirPartyTable.RecId;
  24:          address.update();
  25:   
  26:          //check if GAB mapping has been created
  27:          select dirPartyAddressRelationshipMapping
  28:              where dirPartyAddressRelationshipMapping.AddressRecId == address.RecId &&
  29:                    dirPartyAddressRelationshipMapping.RefCompanyId == address.dataAreaId;
  30:   
  31:          //create GAB mapping if does not exist
  32:          if (!dirPartyAddressRelationshipMapping.RecId)
  33:              DirPartyAddress::insertPartyAddressRelationship(address);
  34:      }
  35:      ;
  36:   
  37:      //select private customer and vendor addresses
  38:      while select address2
  39:          where address2.AddrTableId == tablenum(CustTable) ||
  40:                address2.AddrTableId == tablenum(VendTable)
  41:      {
  42:          try
  43:          {
  44:              ttsbegin;
  45:              convertAddress();
  46:              ttscommit;
  47:          }
  48:          catch (Exception::Deadlock)
  49:          {
  50:              if (xSession::currentRetryCount() >= #RetryNum)
  51:              {
  52:                  throw Exception::Deadlock;
  53:              }
  54:              else
  55:              {
  56:                  retry;
  57:              }
  58:          }
  59:          catch (Exception::UpdateConflict)
  60:          {
  61:              if (appl.ttsLevel() == 0)
  62:              {
  63:                  if (xSession::currentRetryCount() >= #RetryNum)
  64:                  {
  65:                      throw Exception::UpdateConflictNotRecovered;
  66:                  }
  67:                  else
  68:                  {
  69:                      retry;
  70:                  }
  71:              }
  72:              else
  73:              {
  74:                  throw Exception::UpdateConflict;
  75:              }
  76:          }
  77:          catch
  78:          {
  79:              error(strfmt("Conversion failed for address record id %1 in %2 company. \n Correct it and resume conversion again.", address2.RecId, address2.dataAreaId));
  80:          }
  81:      }
  82:   
  83:  }

Popular posts from this blog

Dynamics Axapta: Sales Orders & Business Connector

Well, again folllowing my same idea of writting close to nothing and pasting code, I'll paste in some code to create a sales order from some basic data and the invoice it. I'll try to explain more in the future. AxaptaObject axSalesTable = ax.CreateAxaptaObject("AxSalesTable"); AxaptaRecord rcInventDim = ax.CreateAxaptaRecord("InventDim"); AxaptaRecord rcCustTable = ax.CreateAxaptaRecord("CustTable"); rcCustTable.ExecuteStmt("select * from %1 where %1.AccountNum == '" + MySalesOrderObject.CustAccount + "'"); if (MySalesOrderObject.CurrencyCode.Trim().Length == 0) MySalesOrderObject.CurrencyCode = rcCustTable.get_Field("Currency").ToString().Trim(); string sTaxGroup = rcCustTable.get_Field("taxgroup").ToString().Trim(); //set header level fields axSalesTable.Call("parmSalesName", MySalesOrderObject.SalesName.Trim()); axSalesTable.Call("parmCustAccount", M

Passing values between form and class

Class name is EmplDuplication and Form is EmplTable . void clicked() {    MenuFunction mf;    args args = new Args();    ;     args.record(EmplTable);     mf = new menufunction(identifierstr(EmplDuplication), MenuItemType::Action); mf.run(args); } Meanwhile, in the main() method of the EmplDuplication class, we need to put this Axapta x++ code to get the datasource: static void main(Args args) {     EmplDuplication EmplDuplication; EmplTable localEmplTable; ;     if(args.record().TableId == tablenum(EmplTable)) localEmplTable = args.record();     ... }