Search This Blog

Thursday, November 26, 2020

How to create and post counting journal in AX 2012 using x++

 Counting journal is used to modify the on hand inventory of an item with dimension wise. you can create it from Inventory management / Journals /Item Counting / Counting by front end. 

you can also create and post this journal using x++ as well whenever it is require by using below job

static void CreateCountingJournal(Args _args)

{

    InventJournalTable      inventJournalTable;

    InventJournalTrans      inventJournalTrans;

    InventDim               inventDim;

    InventTable             inventTable;

    JournalCheckPost        inventJournalCheckpost;

    InventQtyJournal        journalQty;

    InventJournalName       inventJournalName;

    JournalNameId           countingJournalNameId;

    ItemId                  itemId;

   


    try

    {

        //Initialization - Start

        countingJournalNameId = "WH_COUNT";

        itemId                = "0000010";  

        journalQty            = 21;  

        inventDim.InventSiteId      = "SiteId"; //SiteId

        inventDim.InventLocationId  = "001"; //Warehouse id

        inventDim.wMSLocationId     = "E1-06-01"; //Location id 

        inventDim.LicensePlateId   = "Test001";

        //Specify any other dimension if any

        inventDim             = InventDim::findOrCreate(inventDim);  

        //Initialization - End

        

        //Creation of header - Start

        InventJournalName = InventJournalName::find(countingJournalNameId);

        inventJournalTable.clear();

        inventJournalTable.initFromInventJournalName(inventJournalName);

        inventJournalTable.NumOfLines = 1;

        inventJournalTable.insert();

        //Creation of Header - End


        //Creation of Lines - start

        inventJournalTrans.clear();

        inventJournalTrans.TransDate        = systemdateget();

        inventJournalTrans.initFromInventJournalTable(inventJournalTable);

        inventJournalTrans.initValue();

        inventTable                         = InventTable::find(ItemId);

        inventJournalTrans.ItemId           = inventTable.ItemId;

        inventJournalTrans.InventDimId      = inventDim.inventDimId;

        inventJournalTrans.inventMovement().journalSetItemId(inventDim);              

        inventJournalTrans.Qty              = journalQty; //Curent onhand qty

        //inventJournalTrans.Counted          = 0 Currently counted qty

        inventJournalTrans.inventMovement().journalSetQty();

        inventJournalTrans.insert();

        //Creation of lines - End

        

        

        //Posting of journal - Start

        inventJournalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);

        inventJournalCheckpost.run();

        //Posting of Journal - End       

                

    }

    catch(Exception::CLRError)

    {

        info(AifUtil::getClrErrorMessage());        

    }

    catch(Exception::Error)

    {

        info("Error");    

    }

       

}


Tuesday, November 24, 2020

Error Synchronize database Cannot execute a data definition language command on (). The SQL database has issued an error.

When production database has been copied to the test database or development database then we usually get below type of error during database synchronization after applying model store.










(C)\Classes\Info\add 0
(S)\Classes\xApplication\dbSynchronize 0
(S)\Classes\Application\dbSynchronize 30
(S)\Classes\SysSqlAdminClass\handleSelectedItems 34
(C)\Forms\SysSqlAdmin\Methods\runThroughTablesAndIndexes 42
(C)\Forms\SysSqlAdmin\Designs\DesignList\buttonSynchronize\Methods\Clicked 6
Info Synchronize database SQL error description: [Microsoft][SQL Server Native Client 11.0][SQL Server]There is already an object named 'I_111882RECID' in the database.
Info Synchronize database SQL statement: ALTER TABLE "DBO".TAXGSTREPORTCONFIGURATIONLINECODE_MY ADD CONSTRAINT I_111882RECID PRIMARY KEY CLUSTERED (RECID) WITH (DATA_COMPRESSION = ROW )
Error Synchronize database Cannot execute a data definition language command on  ().
The SQL database has issued an error.


You can try to solve the problem from below approach

  1.  Just try to synchronize the individual table and check if there will be any database synchronization error or not
  2. Check the SQL dictionary table and filter with the table id check if all the id's are proper or not.
  3. There might be a problem that id of the index on this table already exists on the another table. you can query on the database that on which table this index id is present.
  4. Check if there is any data in it or not if there is no data in it then you can try to delete it from SQL and same time try to sync it from AX. it will regenerate it. 
  

Wednesday, November 18, 2020

How to check progress of backup or restore of database on SQL

Some time in SQL backup or restore database process takes more than the usual time and we are not sure when it will going to be completed. 

you can execute the below query and it will display the current status of it and also the estimated time of completion


SELECT session_id as SPID, command, a.text AS Query, start_time, percent_complete, dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time 

FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a 

WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')


Result will be as per below.



Monday, November 9, 2020

Failed to create a session; confirm that the user has the proper privileges to log on to Microsoft dynamics

Some time we get the below error during the database synchronization in AX 2012. 


There could be many solution for this error
  1. Check all the users in AX specially the service account like bc proxy account, AOS account and batch account. 
  2. if the problem still not solve then check your access on SQL database. 
  3. we have workaround as well. Just uncheck the Execute Business operation in CIL and do the database synchronization again.