Tuesday, 18 May 2021

AX 2012 X++ Consume aif web service by passing list of objects

 1- Create data contract class as below

[DataContractAttribute]

class HP_TestContract

{

    str Id;

    str Name;


[DataMemberAttribute('Id'), SysOperationDisplayOrderAttribute('1')]

public str ParamId(str _Id = Id)

{

    Id = _Id;

    return Id;

}

[DataMemberAttribute('Name'), SysOperationDisplayOrderAttribute('2')]

public str ParamName(str _Name = Name)

{

    Name = _Name;

    return Name;

}

}

2-Add an AIF service method

[SysEntryPointAttribute(true),
DataMemberAttribute("HP_TestContract"),
AifCollectionTypeAttribute("_contactList",Types::Class, classStr(HP_TestContract)),
AifCollectionTypeAttribute("return",Types::Class, classStr(HP_TestContract))]
public List HeshamList(List _contactList)
{
//_contactList = contactList;
return _contactList;
}

Tuesday, 6 April 2021

AX365 Dev machine import and Export restore a DB .bacpac file from the UAT

 Download the  Get sqlpackage .NET Core for Windows


Extract the folder and run the command prompt as an administrator, and run the below command


SqlPackage.exe /a:import /sf:D:\Hesham\SafariUATbackup.bacpac /tsn:localhost /tdn:AxDB /p:CommandTimeout=1200  /ttsc:True


Export 


SqlPackage.exe /a:export /TargetFile:H:\BiKeyDB.bacpac /SourceConnectionString:"Server=localhost;Initial Catalog=AxDB;Persist Security Info=False;User ID=sa;Password=sa;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True;Connection Timeout=1200";




Tuesday, 30 March 2021

AX 365 local Dev VM open AX from outside the network

 In case we need to access the local dev machine F&O go to the below path 


C:\Windows\System32\drivers\etc


edit the host file and add the below last line


10.0.1.120 usnconeboxax1aos.cloud.onebox.dynamics.com


the IP of the dev machine 


Enjoy DAXing

Wednesday, 3 February 2021

AX365 Deploy a package locally

 1-Create a temp folder

2-Extract the package inside the temp folder

3-open the command prompt as administrator and navigate into the temp folder and run the below scripts as below

AXUpdateInstaller.exe generate -runbookid="Safarirunbook" -topologyfile="DefaultTopologyData.xml" -servicemodelfile="DefaultServiceModelData.xml" -runbookfile="Safarirunbook-runbook.xml"


AXUpdateInstaller.exe import -runbookfile="Safarirunbook-runbook.xml"


AXUpdateInstaller.exe execute -runbookid="Safarirunbook"

in case you want to rerun a step call the below

AXUpdateInstaller.exe execute -runbookid=Safarirunbook -rerunstep=7

Tuesday, 2 February 2021

AX365/2012 X++ SQL select statement inside AX

 

  Connection      connection;

        Statement       statement;

        str             query;

        Resultset       resultSet;

        container conComm;

        ;


        // create connection object

        connection = new Connection();


        // create statement

        statement = connection.createStatement();


        // Set the SQL statement

        query = "select ACQUISITIONPRICE,BookID,BookType,Status from AssetBookMerge where AssetID = '" + strAssetId + "'";


        // assert SQL statement execute permission

        new SqlStatementExecutePermission(query).assert();


        // when the query returns result,

        // loop all results for processing

        //BP Deviation documented

        resultSet = statement.executeQuery(query);


        while(resultSet.next())

        {

            // do something with the result

            conComm =[resultSet.getString(1),resultSet.getString(2),resultSet.getString(3),resultSet.getString(4)] ;

        }


        // limit the scope of the assert call

        CodeAccessPermission::revertAssert();

        return conComm;

Wednesday, 13 January 2021

AX X++ get value from Financial dimension

   public str getDimValue(RecId _DefaultDim, str dimName)

  {

      DimensionAttributeValueSetStorage    dimStorage;       


      Counter                                               i;

      str ret="";          


      dimStorage = DimensionAttributeValueSetStorage::find(_DefaultDim);

      for (i=1 ; i<= dimStorage.elements() ; i++)

      {               

          if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == dimName)

          {

              ret =dimStorage.getDisplayValueByIndex(i));

          }       

      }

      return ret;

  }


Reference

Monday, 11 January 2021

AX 365 Create general journal from code x++

   LedgerJournalTable _ledgerJournalTable;

        JournalTableData _journalTableData;

        LedgerjournalTrans _ledgerjournalTrans;

       

        MCRLedgerJournal        journalTable;

        LedgerJournalTableData LedgerJournalTableData;

        NumberSeq _numberSeq;

        LedgerJournalACType _ledgerJournalACType;

        

        RecId _RecId;

        NumberSequenceTable _NumberSequenceTable;      

           


 _LedgerJournalTable.JournalName = 'Journal Name';//HpSetup::getSetup().HpCheque;

             

            _LedgerJournalTable.initFromLedgerJournalName();

            _ledgerJournalTable.Name=strJournalDesc;

            _LedgerJournalTable.insert();

            if (_ledgerJournalTable.RecId)

            {


                //_numberSeq = NumberSeq::newGetVoucherFromCode("Alloc_01");

                _RecId =  LedgerJournalName::find(HpSetup::getSetup().HpCheque).NumberSequenceTable;


                select firstonly  _NumberSequenceTable

                    where _NumberSequenceTable.RecId == _RecId;


                _numberSeq = NumberSeq::newGetVoucherFromCode(_NumberSequenceTable.NumberSequence);


                _ledgerjournalTrans.clear();

                _ledgerjournalTrans.initvalue();

                _LedgerJournalTrans.voucher = _numberSeq.voucher();

                _ledgerjournalTrans.JournalNum = _ledgerJournalTable.JournalNum;

                //_ledgerjournalTrans.Company = curext();

                _ledgerjournalTrans.TransDate = HpCheque.TransDate;

                _ledgerjournalTrans.CurrencyCode = CompanyInfoHelper::standardCurrency();

                _ledgerjournalTrans.Txt = "Transafer to cash";

                _ledgerjournalTrans.AccountType = LedgerJournalACType::Cust;

                _ledgerjournalTrans.LedgerDimension = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(HpCheque.CustAccount,LedgerJournalACType::Cust);

                _ledgerjournalTrans.OffsetAccountType = LedgerJournalACType::Bank;

                _ledgerjournalTrans.OffsetLedgerDimension = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber(dialogField.value(),LedgerJournalACType::Bank) ;

                _ledgerjournalTrans.AmountCurCredit = HpCheque.TrxAmount;

                    

                _ledgerjournalTrans.insert();