Tuesday, January 5, 2016

Query SQL Server Database Create date and last restore date and other info


Query SQL Server Database Create date and Last restore date 



WITH LastRestores AS
(
SELECT
    DatabaseName = [d].[name] ,
    [d].[create_date] ,
    [d].[compatibility_level] ,
    [d].[collation_name] ,
    r.*,
    RowNum = ROW_NUMBER() OVER (PARTITION BY d.Name ORDER BY r.[restore_date] DESC)
FROM master.sys.databases d
LEFT OUTER JOIN msdb.dbo.[restorehistory] r ON r.[destination_database_name] = d.Name
)
SELECT *
FROM [LastRestores]
WHERE [RowNum] = 1






Friday, November 27, 2015

Dynamics AX 2012 create and post General Journal Using X++

Create and  post General Journal Using X++

static void CreateGLJournalPost(Args _args)
{
AxLedgerJournalTable journalTable
AxLedgerJournalTrans journalTrans;
   
container acctPattern;
container offSetAcctPattern;
LedgerJournalTable ledgerJournalTable;
ledgerJournalCheckPost ledgerJournalCheckPost;

;
   
   
journalTable = new AxLedgerJournalTable();
journalTrans = new AxLedgerJournalTrans();
   
//Journal Name
journalTable.parmJournalName("GL");
journalTable.save();

journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans.parmTransDate(systemDateGet());
journalTrans.parmCurrencyCode("SAR");
journalTrans.parmAmountCurDebit(1200);
   

acctPattern = ["11030101-01-02","11030101", 2, "Region","01","Branch", "02"];
journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(acctPattern));
journalTrans.parmAccountType(LedgerJournalACType::Ledger);
   

offSetAcctPattern = ["41010101-01-02","41010101", 2, "Region","01","Branch", "02"];
journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern));
journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger );
journalTrans.save();

ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
ledgerJournalCheckPost.run();
info(strFmt("Journal No. %1.", journalTable.ledgerJournalTable().JournalNum));
}

Thanks

axLedgerJournalTrans.parmOffsetLedgerDimension is not working in Dynamics AX2012 R3


if you try to create general journal in AX 2012 R3 and the offset Account not set and you are using such of following code


journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger ); 
offSetAcctPattern = ["41010101-01-02","41010101", 2, "Region","01","Branch", "02"]; 
journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern)); 
journalTrans.save(); 



Solution is simply:
Reverse the code order to be 


offSetAcctPattern = ["41010101-01-02","41010101", 2, "Region","01","Branch", "02"]; 
journalTrans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern)); 
journalTrans.parmOffsetAccountType(LedgerJournalACType:: Ledger ); 
journalTrans.save(); 







Sunday, September 30, 2012

Step to Add new Number Sequence



Here is the simplest steps  to create new number sequence

Steps :

1- Add this code in loadModule() method  on proper number sequence class  , every dynamics ax module has its own number sequence class , here I use Sales and Marketing module  and the class is NumberSeqModuleCRM


     /* Setup Analysis Id numbers sequence   */
    datatype.parmDatatypeId(extendedtypenum(AnalysisId));
    datatype.parmConfigurationKeyId(configurationkeynum(SmmCRM));
    datatype.parmReferenceHelp(literalstr("Shabakah  analysis Requirement reference"));
    datatype.parmWizardIsContinuous(true);
    datatype.parmWizardIsManual(NoYes::No);
    datatype.parmWizardIsChangeDownAllowed(NoYes::No);
    datatype.parmWizardIsChangeUpAllowed(NoYes::No);
    datatype.parmSortField(4);
    datatype.parmWizardHighest(999999);

    datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
    this.create(datatype);



2 - In class declration of Form

 NumberSeqFormHandler numberSeqFormHandler;



3- create new method in form level

NumberSeqFormHandler numberSeqFormHandler()
{

if (!numberSeqFormHandler)
{

numberSeqFormHandler = NumberSeqFormHandler::newForm(NumberSeqReference::findReference(extendedTypeNum(AnalysisId)).NumberSequenceId,
element,
Analysis_ds,
fieldNum(Analysis, AnalysisId));

}

return numberSeqFormHandler;
}



4- Add this code after super()  in datasource create()  method


element.numberSeqFormHandler().formMethodDataSourceCreate();



5 -  Run this code  in job

    NumberSeqModuleCRM   crm = new NumberSeqModuleCRM();
    crm.load();



6- Make Generate number sequence from Organization Administration



Friday, March 30, 2012

SQL Server database marked as suspect

Today the Dynamics AX 2012 service couldn't start in my Test Server , after looking to log file i found  the administrator doesn't  have access to  Dynamics ax 2012 database , switch to Sqlserver i found that my AX database  is marked Suspect ,after Google this problem I found the  following script
and able to solve this issue



EXEC sp_resetstatus 'MicrosoftDynamicsAX';
ALTER DATABASE MicrosoftDynamicsAX SET EMERGENCY
DBCC checkdb('MicrosoftDynamicsAX')
ALTER DATABASE MicrosoftDynamicsAX SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('MicrosoftDynamicsAX', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE MicrosoftDynamicsAX SET MULTI_USER


Happy DAX

Wednesday, December 21, 2011

6 steps to take backup of all the objects from 'user' layer


6 steps to take backup of all the objects from 'user' layer

While working on client side with lot of customizations, someone must take the backup of all the changes which already have done in an application.

A very short way of taking backup from a selected layer is as follows;

1. Create a new project and open it.
2. Click on the Advance filter/Sort for this project, it will open the following screen


Note: Make sure the above options should be selected for this scenario.

3. Click on ‘Select’ button.
4. Remove all the ranges from this query form and add only one range. The form will now looks like this;



5. Press OK, form will be closed
6. Press OK

The new project will contains the entire objects, group by their consecutive groups.