Friday 16 December 2016

When was the last time your SQL Server database was restored

Select Destination_database_name, restore_date, database_name as Source_database, Physical_device_name as Backup_file_used_to_restore, bs.user_name, bs.machine_name from msdb.dbo.restorehistory rh inner join msdb.dbo.backupset bs on rh.backup_set_id=bs.backup_set_id inner join msdb.dbo.backupmediafamily bmf on bs.media_set_id =bmf.media_set_id ORDER BY [rh].[restore_date] DESC

Thursday 17 November 2016

Import and create GL transactions (Ledger and Project type) into AX 2012 using x++ code - csv file

#public class LedgerImportNew extends RunBase
        #{
        #    CommaIo                     csvFile;
        #    Filename                    filename;
        #    DialogField                 dialogFilename;
        #    container                   readCon;
        #    container                   ledgerDimensions, offsetDimensions;
        #    counter                     icount,inserted;
        #    Amount                      amount;
        #    LedgerJournalACType         ledgerJournalACType;
        #    ledgerJournalName           ledgerJournalName;
        #    LedgerJournalTable          ledgerJournalTable;
        #    LedgerJournalTrans          ledgerJournalTrans;
        #    LedgerJournalTrans_Project  ledgerProjects;
        #
        #
        #    #define.CurrentVersion(2)
        #    #localmacro.CurrentList
        #        filename,
        #        insertIncorrectRecords,
        #    #endmacro
        #
        #    #localmacro.ListVersion1
        #        filename,
        #        insertIncorrectRecords
        #    #endmacro
        #
        #    #File
        #
        #}

        #public Object dialog()
        #{
        #    DialogRunbase       dialog = super();
        #    ;
        #    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));
        #
        #    dialogFilename.value(filename);
        #    dialog.filenameLookupFilter(["All files", #AllFiles]);
        #
        #    return dialog;
        #}
        #

        #public boolean getFromDialog()
        #{
        #    filename                = dialogFilename.value();
        #
        #    return true;
        #}

        #public LedgerDimensionAccount getLedgerDimension(AccountNum _accountNum)
        #{
        #    MainAccount                 mainAccount;
        #
        #    RefRecId                    accountStructureId;
        #    List                        dimensionList = new List(Types::Class);
        #    DimensionDefaultingEngine   dimensionDefaultingEngine;
        #    ;
        #
        #    mainAccount = MainAccount::findByMainAccountId(_accountNum);
        #
        #    accountStructureId = DimensionHierarchy::getAccountStructure(mainAccount.RecId);
        #
        #    if(mainAccount)
        #    {
        #        dimensionDefaultingEngine = DimensionDefaultingEngine::constructForMainAccountId(mainAccount.RecId, accountStructureId);
        #        dimensionDefaultingEngine.applyDimensionSources(dimensionList);
        #
        #        return dimensionDefaultingEngine.getLedgerDimension();
        #    }
        #    else
        #        return 0;
        #}

        #void run()
        #{
        #    boolean                             first = true;
        #    MainAccount                         mainAccount;
        #    DimensionAttributeValueCombination  dimensionAttributeValueCombination;
        #    MainAccountNum                      mainAccountNum;
        #    NumberSequenceTable                 numberSequenceTable;
        #    LedgerJournalEngine_Daily           ledgerJournalEngine_Daily;
        #    Voucher                             voucher;
        #    DimensionLedgerAccountType          ledgerAccountType;
        #    str                                 accountType;
        #    Amount                              amountCurDebit,amountCurCredit;
        #    container                           conSplitValue;
        #    projTable                           projTable;
        #    DimensionAttributeValueCombination  ledgerDimension;
        #    ProjId                              projid;
        #    ;
        #
        #    csvFile = new CommaIO(filename, 'r');
        #    try
        #    {
        #        if (csvFile)
        #        {
        #            ttsbegin;
        #            if(first) //Create Journal Header
        #            {
        #                select firstOnly ledgerJournalName where ledgerJournalName.JournalType == LedgerJournalType::Daily;
        #
        #                if(!ledgerJournalName.RecId)
        #                {
        #                    throw error ("ledgerJournalName doesn't exgist");
        #                }
        #
        #                ledgerJournalTable.clear();
        #                ledgerJournalTable.initValue();
        #                ledgerJournalTable.JournalNum    = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
        #                ledgerJournalTable.journalType   = LedgerJournalType::Daily;
        #                ledgerJournalTable.JournalName   = ledgerJournalName.JournalName;
        #                ledgerJournalTable.Name          = ledgerJournalName.Name;
        #                ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
        #                ledgerJournalTable.insert();
        #
        #                first = false;
        #            }
        #
        #            numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(ledgerJournalTable.JournalName).NumberSequenceTable);
        #
        #            voucher =  NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();
        #
        #            while (csvFile.status() == IO_Status::OK)
        #            {
        #                readCon = csvFile.read();
        #
        #                icount++;
        #
        #                amountCurDebit = 0;
        #                amountCurCredit = 0;
        #
        #                if (readCon && icount > 1)//dont insert first record of file : header
        #                {
        #                    amountCurDebit = conPeek(readCon,7);
        #                    amountCurCredit = conPeek(readCon,8);
        #
        #                    //split and read accountNumber and Department values
        #                    //AccountNum = conpeek(conSplitValue,1)
        #                    //Department = conpeek(conSplitValue,2)
        #                    conSplitValue = this.splitAccountNumAndDept(strLRTrim(conPeek(readCon,5)));
        #
        #                    if(amountCurDebit > 0 || amountCurCredit > 0)
        #                    {
        #                        //Create Trans ...
        #
        #                        ledgerJournalTrans.clear();
        #                        ledgerJournalTrans.initValue();
        #                        ledgerJournalTrans.JournalNum         = ledgerJournalTable.JournalNum ;
        #                        ledgerJournalTrans.Txt                = conPeek(readCon,6);
        #                        ledgerJournalTrans.transDate          = str2Date(conPeek(readCon,1),213);
        #
        #                        accountType = strLRTrim(conPeek(readCon,3));
        #
        #                        if(enum2str(LedgerJournalACType::Project) == accountType)
        #                        {
        #                            ledgerJournalTrans.AccountType   = LedgerJournalACType::Project;
        #                        }
        #                        else if(accountType == "")
        #                        {
        #                            ledgerJournalTrans.AccountType   = LedgerJournalACType::Ledger;
        #                        }
        #
        #                       //use the below code if need to read account type from account number
/* type              = enum2str(MainAccount::findByMainAccountId(strLRTrim(conPeek(conSplitValue,1))).Type);
        #
        #                        if(enum2str(LedgerJournalACType::Bank) == type)
        #                        ledgerJournalTrans.AccountType   = LedgerJournalACType::Bank;
        #                        else if(enum2str(LedgerJournalACType::Cust) == type)
        #                        ledgerJournalTrans.AccountType   = LedgerJournalACType::Cust;
        #                        else if(enum2str(LedgerJournalACType::FixedAssets) == type)
        #                        ledgerJournalTrans.AccountType   = LedgerJournalACType::FixedAssets;
        #                        else if(enum2str(LedgerJournalACType::Ledger) == type)
        #                        ledgerJournalTrans.AccountType   = LedgerJournalACType::Ledger;
        #                        else if(enum2str(LedgerJournalACType::Project) == type)
        #                        ledgerJournalTrans.AccountType   = LedgerJournalACType::Project;
        #                        else if(enum2str(LedgerJournalACType::Vend) == type)
        #                        ledgerJournalTrans.AccountType   = LedgerJournalACType::Vend;*/
        #
        #                        if( ledgerJournalTrans.AccountType   == LedgerJournalACType::Project)
        #                        {
        #                            projid = strLRTrim(conPeek(readCon,5));
        #
        #                            select firstonly projTable join RecId from ledgerDimension where ledgerDimension.DisplayValue == projTable.ProjId && projTable.ProjId == projid;
        #
        #                            ledgerJournalTrans.LedgerDimension = ledgerDimension.RecId;
        #                        }
        #                        else
        #                        {
        #                            ledgerJournalTrans.LedgerDimension    = this.getLedgerDimension(strLRTrim(conPeek(conSplitValue,1)));
        #                        }
        #
        #                        ledgerJournalTrans.AmountCurDebit     = amountCurDebit;
        #                        ledgerJournalTrans.AmountCurCredit    = amountCurCredit;
        #                        ledgerJournalTrans.Company            = strLRTrim(conPeek(readCon,2));
        #                        ledgerJournalTrans.CurrencyCode       = strLRTrim(conPeek(readCon,9));
        #                        ledgerJournalTrans.voucher = voucher;
        #                        ledgerJournalTrans.insert();
        #
        #                        if( ledgerJournalTrans.AccountType   == LedgerJournalACType::Project)
        #                        {
        #
        #                           if(!LedgerJournalTrans_Project::checkExist(ledgerJournalTrans.RecId))
        #                           {
        #                                ledgerProjects.clear();
        #                                ledgerProjects.initValue();
        #                                ledgerProjects.CategoryId = strLRTrim(conPeek(readCon,4));
        #                                ledgerProjects.RefRecId = ledgerJournalTrans.RecId;
        #                                ledgerProjects.ProjId = strLRTrim(conPeek(readCon,5));
        #                                ledgerProjects.insert();
        #                            }
        #                            else
        #                            {
        #                                select forUpdate ledgerProjects where ledgerProjects.RefRecId==ledgerJournalTrans.RecId;
        #
        #                                if(ledgerProjects)
        #                                {
        #                                    ledgerProjects.CategoryId = strLRTrim(conPeek(readCon,4));
        #                                    ledgerProjects.ProjId = strLRTrim(conPeek(readCon,5));
        #                                    ledgerProjects.update();
        #                                }
        #                        }
        #                     }
        #                        //Record inserted count
        #                        inserted++;
        #                    }
        #
        #                }
        #            }
        #
        #            ttsCommit;
        #        }
        #
        #        icount--;//Remove header recount from total record count
        #    }
        #    catch(Exception::Error)
        #    {
        #       info(strFmt("%1",Exception::Error));
        #    }
        #
        #    info(strfmt("%1 records inserted out of %2",inserted,icount));
        #}

        #public container splitAccountNumAndDept(str _accountNumDept, str _separator = '-')
        #{
        #
        #    int     separatorPosition;
        #    container con;
        #
        #    ;
        #
        #        separatorPosition = strfind(_accountNumDept, _separator, strlen(_accountNumDept), -strlen(_accountNumDept));
        #
        #        if(separatorPosition)
        #        {
        #            //AccountNumber
        #            con = conIns(con, 1,substr(_accountNumDept, 1, separatorPosition - 1));
        #            //Department
        #            con = conIns(con, 2,substr(_accountNumDept, separatorPosition + 1, 3));
        #
        #        }
        #        else
        #        {
        #            //AccountNumber
        #            con = conIns(con, 1,_accountNumDept);
        #
        #        }
        #
        #    return con;
        #}

        #static void main(Args  args)
        #{
        #    LedgerImportNew        ledgerImportNew;
        #
        #    ;
        #
        #    ledgerImportNew =  new LedgerImportNew();
        #
        #    if(ledgerImportNew.prompt())
        #    {
        #        ledgerImportNew.run();
        #    }
        #

Thursday 27 October 2016

Error message when activating inbound port in Aif: "There is already a listener on IP endpoint"

Solution :  Stop AOS.
Delete the files under XPPIL directory located under Server BIN directory.
Truncate table (SysXPPAssembly) from SQL.
Restart the AOS.
Basically the IL binary files which are saved in this table might have been messed up there! On the AOS restart it produces the binaries freshly and updates the table which should fix the issue.

HTTP Error 503: Service unavailable

  1. Go to the respective application pool in IIS and check whether the service is running or not. If not start the service. 
  2. If the service is getting stopped and got the same error when you browse the server. Check the Identity credentials in advanced settings of the application pool.It may cause due to change of the system credentials.

"HTTP Error 403.14 - Forbidden" error when you open an IIS 7.0 Webpage

Symptoms
You have a Web site that is hosted on Internet Information Services (IIS) 7.0. When you visit the Web site in a Web browser, you may receive an error message that resembles the following:
Server Error in Application "application name"

HTTP Error 403.14 - Forbidden

HRESULT: 0x00000000

Description of HRESULT : The Web server is configured to not list the contents of this directory.
Resolution

For end-users

If you are an end-user, you should contact the website administrators in order to let them know that this error has occurred for this URL address. Then, the website administrators will fix this issue later.

For site administrators

This problem occurs because the Web site does not have the Directory Browsing feature enabled, and the default document is not configured. To resolve this problem, use one of the following methods:

Method 1: Enable the Directory Browsing feature in IIS (Recommended)

To resolve this problem, follow these steps:
  1. Start IIS Manager. To do this, click Start, click Run, type inetmgr.exe, and then click OK.
  2. In IIS Manager, expand server name, expand Web sites, and then click the website that you want to modify.
  3. In the Features view, double-click Directory Browsing.
  4. In the Actions pane, click Enable.

Method 2: Add a default document

To resolve this problem, follow these steps:
  1. Start IIS Manager. To do this, click Start, click Run, type inetmgr.exe, and then click OK.
  2. In IIS Manager, expand server name, expand Web sites, and then click the website that you want to modify.
  3. In the Features view, double-click Default Document.
  4. In the Actions pane, click Enable.
  5. In the File Name box, type the name of the default document, and then click OK.

Method 3: Enable the Directory Browsing feature in IIS Express

Note This method is for the web developers who experience the issue when they use IIS Express.

To do this, follow these steps:
  1. Open a command prompt, and then go to the IIS Express folder on your computer. For example, go to the following folder in a command prompt: 
    C:\Program Files\IIS Express
  2. Type the following command, and then press Enter: 
    appcmd set config /section:directoryBrowse /enabled:true

Thursday 28 April 2016

AX 2012 TFS: Solving update conflicted FK_ModelElementData_HasModelId_LayerId and XU_Update error with SQL profiler

When using AX 2012 with TFS, sometimes you'll get a cryptic error during a TFS synchronization like this:

SQL error description: [Microsoft][SQL Server Native Client 10.0][SQL Server]The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_ModelElementData_HasModelId_LayerId". The conflict occurred in database "Dev5_AX2012_model", table "dbo.Model".
SQL statement: { CALL [Dev5_AX2012_model].[dbo].[XU_Update](?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }
Cannot execute a stored procedure.

Solution : Restart the AOS Services.

Thursday 7 April 2016

Printing dynamic parameters (AX 2012 / SSRS)

In addition to parameters specified in data contracts, reports can also use queries. It’s very handy, because users can specify filters and sorting in exactly the same way as they’re used to from other places in Dynamics AX, they can use query expressions and so on.
ReportDialog

RangeSelection
A relative common request is printing parameter values on the report itself. It’s easy with parameters defined in data contracts – an expression like =Parameters!UsersToInclude.Value will do the job. But the same approach doesn’t work with dynamic parameters (that’s how query parameters get represented in SSRS).
I recommend the following approach. Use a report data provider class – very often, it’s already in place. Add a new data table to hold information about query ranges and expose it to the report. I’m using an existing table, TmpSysQuery, so we don’t have to discuss the design of the table. InprocessReport(), we extract ranges from the current query and save them to our temporary table.
Because the logic for extracting ranges from a Query object may be needed from other places as well, I’ve put it into a separate class. This is the content of the method:
///use this code
SignTestTmp.Name = query.dataSourceTable(tablenum(UserInfo)).range(1).value();
///or
public static TmpSysQuery rangesToTable(Query _query)
{
    QueryBuildDataSource    qbds;
    QueryBuildRange         queryBuildRange;
    TmpSysQuery             tmpSysQuery;
    LabelType               tableLabel;
    int                     occurrence;
    int                     dataSourceNo;
    int                     i;
 
    if (!_query)
    {
        return tmpSysQuery;
    }
 
    for (dataSourceNo = 1; dataSourceNo <= _query.dataSourceCount(); dataSourceNo++)
    {
        qbds = _query.dataSourceNo(dataSourceNo);
        if (qbds.enabled())
        {
            occurrence = SysQuery::tableOccurrence(_query, qbds.table(), dataSourceNo);
            tableLabel = tableId2pname(qbds.table()) + SysQuery::tableOccurrenceText(occurrence);
 
            for (i = 1; i <= qbds.rangeCount(); i++)
            {
                queryBuildRange = qbds.range(i);
 
                if (queryBuildRange.value() && queryBuildRange.status() != RangeStatus::Hidden)
                {
                    tmpSysQuery.clear();
                    tmpSysQuery.DataSourceNo = qbds.uniqueId();
                    tmpSysQuery.TableLabel   = tableLabel;
                    tmpSysQuery.FieldLabel   = fieldId2pname(qbds.table(), queryBuildRange.field());
                    tmpSysQuery.RangeValue   = queryBuildRange.value();
                    tmpSysQuery.insert();
                }
            }
        }
    }
 
    return tmpSysQuery;
}

Tuesday 19 January 2016

Move File From One Folder To Another Folder Using X++

Hi Guys . I hope you are doing Good.
Today i’m going to share you that , how to move a File from One Folder to another folder using X++.
Here we can achieve this with the Help of WINAPI(Windows Application Programming Interface). Even though we can do Copy a file, delete a file, Create Directory, getting the file Size, etc. Refer more Details WINAPI
static void MoveFilesFromFoldertoAnotherFolder(Args _args)
{
 FilenameOpen fileNameOpen;
 DialogField dialogFileName;
 Dialog dialog;
 Filename filePath;
 Filename fileName;
 Filename fileType;
 FileName DestinationPath;
 #File
 
 ;
DestinationPath = @'C:\Users\saadullah\Desktop\Dest\'; // Define your Destination Path
 dialog = new Dialog("Move Files");
// AX 2009
 dialogFilename = dialog.addField(typeId(FileNameOpen));
// AX 2012
 // dialogFileName = dialog.addField(extendedTypeStr(FileNameOpen));
dialog.filenameLookupFilter([#AllFilesType]);
 dialog.filenameLookupTitle("Select File");
 dialog.caption("Move File");
 dialogFilename.value(fileName);
if(!dialog.run())
 return;
filenameOpen = dialogFilename.value();
 [filePath, fileName, fileType] = fileNameSplit(fileNameOpen);
// MoveFile - The Original File won't be available once it's moved into destination path
WinAPI::moveFile(fileNameOpen, DestinationPath+FileName+FileType);
// CopyFile - The Original File will be available even if it's moved into destination path
 //WinAPI::copyFile(fileNameOpen, DestinationPath+FileName+FileType);
// DeleteFile - Delete the Selected File
 //WinAPI::deleteFile(fileNameOpen);
 
 // If u need to Use this in Form Take look in AOT > Forms > Tutorial_Form_File
}