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

Mark All for Open Cust Trans and Open Vend Trans

We have situations where there are lots of open transactions that need to be settled against each other. This can be the case if auto settlement is turned off. One solution is to add a "Mark All" button to the custOpenTrans or vendOpenTrans forms. This button "checks" the mark checkbox on every line. The user can then uncheck several lines if needed and Update to settle the lines. The code below is an example of what we used on the open vendor transaction screen. The code is very similar on the AR side. One note: I used vendTable.AccountNum in the code below. That should be generalized to work with any buffer that is passed into the open trans form. void customMarkAll() { VendTransOpen localVendTransOpen; VendTrans localVendTrans; container conSum; int linesProcessed; ; //show wait cursor startLengthyOperation(); element.lock(); //remove all prior markings specOffsetVoucher.deleteSpe...

Print Report in Microsoft Dynamics AX 2009 through X++

I am trying to print sales confirmation report on a button click which I have added on Sales Order Detail form in Microsoft Dynamics AX 2009. On click event of that button, I have written following code: void clicked() {     Args                args;     ReportRun           reportRun;     SalesFormLetter     salesFormLetter;     PrintJobSettings    printJobSettings;     CustConfirmJour     custConfirmJour;     RecordSortedList    list                = new RecordSortedList(55);     SalesTable          salesTableUpdate;     ;     SELEC...

Creating Free Text Invoice through X++ code

Job: Calling class from job to run the class public void freeTextInvoicePostTestJob() { Dialog dialog; DialogField dlgCustAcc; DialogGroup dialogPeriodLengthGroup, dialogPeriodLengthGroup1; DialogField dlgLedgerAcc; ; dialog = new Dialog("Free-Text Invoice"); dialogPeriodLengthGroup1 = dialog.addGroup('Cust Table'); dlgCustAcc = dialog.addField(typeid(CustAccount)); dialogPeriodLengthGroup = dialog.addGroup('Ledger Table'); dlgLedgerAcc = dialog.addField(typeid(LedgerAccount)); if(dialog.run()) { if(dlgCustAcc.value() && dlgLedgerAcc.value() != '') FreeTxtInvoiceCreatePost::main(dlgCustAcc.value(), dlgLedgerAcc.value()); else throw error(strfmt("Either CustAccount or LedgerAccount info is missing.")); } } Class: Which creates the free text invoice class FreeTxtInvoiceCreatePost { } static void main(CustAccount _custAccount, LedgerAccount _ledgerAccount) { CustInvoiceTable custInvoiceTable; ...