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

What does this mean: "The form datasource query object does not support changing its AllowCrossCompany property after the form has executed the query."?

I have made a form with datasources vendtable and vendtrans. Inside vendtable_ds.executequery() looks like this: QueryBuildDataSource queryBuildDatasource ,queryBDS_VendTrans_Invoice; ; queryBuildDatasource = this.query().dataSourceTable(tablenum(vendtable)); queryBDS_VendTrans_Invoice = this.query().dataSourceTable(tablenum(vendtrans)); if (curext() == "MASTERCOMP") { this.query().allowCrossCompany(true); } else { this.query().allowCrossCompany(false); } //FilterVendorName = stringedit control on form if (FilterVendorName.text()) { queryBuildDatasource.addRange(fieldNum(VendTable,Name)).value(strfmt("*%1*", FilterVendorName.text())); } else { queryBuildDatasource.clearRange(fieldNum(VendTable,Name)); } //FilterInvoiceNumber = stringedit control on form if (FilterInvoiceNumber.valueStr() == "") { queryBDS_VendTrans_Invoice.enabled(false); } else { queryBDS_VendTrans_Invoice.enabled(true); queryBDS_VendTrans_In...

Credit Note [Dynamics AX] using X++

This post will help to create credit note for a sales order based on the invent lot id. All the invoices raised for a particular sales line – Lot Id will be raised back as a credit note. Information on Credit Note: A credit note or credit memorandum (memo) is a commercial document issued by a seller to a buyer. The seller usually issues a Credit Memo for the same or lower amount than the invoice, and then repays the money to the buyer or sets it off against a balance due from other transactions Below Code will help to create credit note for all the invoices raised against the sales line -lot id. Please note: This code can be customized as per your requirements. This is just a template to help creating credit note using X++ code. Please test the code before use. static void SR_CreateCreditNote_Sales(Args _args) { // Coded by Sreenath Reddy CustInvoiceTrans custInvoiceTrans; Dialog dialog = new Dialog(“Create credit note – for sales.”); DialogField dfInv...