Showing posts with label Development. Show all posts
Showing posts with label Development. Show all posts

Thursday, April 7, 2016

MB6-890 Microsoft Development Introduction - AX7 (Rainer) - Exam Topics

Exam Topics
Understand the Architecture and Development Environment (20% - 25%)
Understand the Architecture and Development Environment
This objective may include but is not limited to: identify features of Microsoft Dynamics AX; describe the development environment; describe the components in the application stack; identify cloud architecture components; explain the server architecture; describe the layer architecture.
Use Microsoft Visual Studio to manage development with Microsoft Dynamics AX
This objective may include but is not limited to: identify the windows and basic navigation of Visual Studio; describe differences between and uses for projects, models, solutions, and packages.

Use the Application Explorer to Develop New Elements (25% - 30%)
Create and manage labels and resources
This objective may include but is not limited to: create new label files; create and use labels; describe elements and uses for labels; identify best practices for labels identify uses for resources.
Create and manage data types
This objective may include but is not limited to: describe uses for base enumerations; create new base enumerations; identify best practices for base enumerations; describe primitive and extended data types; create new extended data types; identify key properties for extended data types; implement best practices for extended data types.
Create and manage tables
This objective may include but is not limited to: identify the components of a table; describe various types of table relationships; describe various types of table indexes; implement best practices for tables, relationships, and indexes.
                                                        
Read, Write and Understand Basic X++ (30% - 35%)
Describe X++
This objective may include but is not limited to: identify the characteristics of X++; use the code editor to write X++; describe the features of IntelliSense; identify basic syntax for X++; describe the use of common key words in X++; describe the features of the debugger; use the comparison tool; use the best practice checker.
Work with X++ control statements
This objective may include but is not limited to: work with variables, operators, conditional statements, and loops; use built-in functions; use communication tools.
Work with classes
This objective may include but is not limited to: create new classes; describe scoping events and parameters; describe inheritance; identify key best practices when writing X++.
Use X++ to manipulate data
This objective may include but is not limited to: identify techniques for data retrieval; explain uses for transaction integrity checking; insert, update, and delete records using X++; identify best practices for manipulating data with X++.
Manage exceptions in X++
This objective may include but is not limited to: identify exception types; use try/catch statements; describe the features of optimistic concurrency control; describe best practices for exception handling with X++ .

Manage the User Interface and Security for Developers  (20% - 25%)
Manage the user interface
This objective may include but is not limited to: identify components of various form patterns; identify common form patterns and sub patterns; identify key properties for form elements; apply and validate form patterns; describe uses for tiles; describe how to join data in forms; implement best practices for form development.
Manage user navigation
This objective may include but is not limited to: identify types of menu items; create menu items and menus; identify key properties for menu items; describe uses for menu items; implement best practices for menus and menu items.
Manage security in the development environment
This objective may include but is not limited to: describe the security architecture; describe the components of role-based security; create new privileges, duties, and roles in the application explorer; describe the extensible data security framework.

Tuesday, October 13, 2015

AX DB Restore Scripts - Moving AX DB from one server to another server

Following SQL script is very useful while moving AX DB from one server to other server. Thanks to http://www.exploreax.com.

Declare @AOS varchar(30) = '[AOSID]' --must be in the format '01@SEVERNAME'
---Reporting Services---
Declare @REPORTINSTANCE varchar(50) = 'AX'
Declare @REPORTMANAGERURL varchar(100) = 'http://[DESTINATIONSERVERNAME]/Reports_AX'
Declare @REPORTSERVERURL varchar(100) = 'http://[DESTINATIONSERVERNAME]/ReportServer_AX'
Declare @REPORTCONFIGURATIONID varchar(100) = '[UNIQUECONFIGID]'
Declare @REPORTSERVERID varchar(15) = '[DESTINATIONSERVERNAME]'
Declare @REPORTFOLDER varchar(20) = 'DynamicsAX'
Declare @REPORTDESCRIPTION varchar(30) = 'Dev SSRS';

---SSAS Services---
Declare @SSASSERVERNAME varchar(20) = '[YOURSERVERNAME]\AX'
Declare @SSASDESCRIPTION varchar(30) = 'Dev SSAS'; -- Description of the server configuration

---BC Proxy Details ---
Declare @BCPSID varchar(50) = '[BCPROXY_SID]'
Declare @BCPDOMAIN varchar(50) = '[yourdomain]'
Declare @BCPALIAS varchar(50) = '[bcproxyalias]'
---Service Accounts ---
Declare @WFEXECUTIONACCOUNT varchar(20) = 'wfexc'
Declare @PROJSYNCACCOUNT varchar(20) = 'syncex'
---Help Server URL---
Declare @helpserver varchar(200) = 'http://[YOURSERVER]/DynamicsAX6HelpServer/HelpService.svc'

---Outgoing Email Settings---
Declare @SMTP_SERVER varchar(100) = 'smtp.mydomain.com' --Your SMTP Server
Declare @SMTP_PORT int = 25
---DMF Folder Settings ---
Declare @DMFFolder varchar(100) = '\\[YOUR FILE SERVER]\AX import\ '

---Email Template Settings---
Declare @EMAIL_TEMPLATE_NAME varchar(50) = 'Dynamics AX Workflow QA - TESTING'
Declare @EMAIL_TEMPLATE_ADDRESS varchar(50) = 'workflowqa@mydomain.com'
---Email Address Clearing Settings---
DECLARE @ExclUserTable TABLE (id varchar(10))
insert into @ExclUserTable values ('userid1'), ('userid2')

--List of users separated by | to keep enabled, while disabling all others
Declare @ENABLE_USERS NVarchar(max) = '|Admin|TIM|'
--List of users separated by | to disable, while keeping all the rest enabled all others
--Declare @DISABLE_USERS NVarchar(max) = '|BOB|JANE|'

--*****BEGIN UPDATES*******---

---Update AOS Config---
delete from SYSSERVERCONFIG where RecId not in (select min(recId) from SYSSERVERCONFIG)
update SYSSERVERCONFIG set serverid=@AOS, ENABLEBATCH=1
where serverid != @AOS -- Optional if you want to see the "affected row count" after execution.

---Update Batch Servers---
delete from BATCHSERVERGROUP where RecId not in (select min(recId) from BATCHSERVERGROUP group by GROUPID)
update BATCHSERVERGROUP set SERVERID=@AOS
where serverid != @AOS -- Optional to see "affected row count"
update batchjob set batchjob.status=4 where batchjob.CAPTION = '[BATCHJOBNAME]'
update batch set batch.STATUS=4 from batch inner join BATCHJOB on BATCHJOBID=BATCHJOB.RECID AND batchjob.CAPTION = '[BATCHJOBNAME]'

---Update Reporting Services---
delete from SRSSERVERS where RecId not in (select min(recId) from SRSSERVERS)
update SRSSERVERS set
    SERVERID=@REPORTSERVERID,
    SERVERURL=@REPORTSERVERURL,
    AXAPTAREPORTFOLDER=@REPORTFOLDER,
    REPORTMANAGERURL=@REPORTMANAGERURL,
    SERVERINSTANCE=@REPORTINSTANCE,
    AOSID=@AOS,
    CONFIGURATIONID=@REPORTCONFIGURATIONID,
    DESCRIPTION=@REPORTDESCRIPTION
where SERVERID != @REPORTSERVERID -- Optional if you want to see the "affected row count" after execution.

---Update SSAS Services---
delete from BIAnalysisServer where RecId not in (select min(recId) from BIAnalysisServer)
update BIAnalysisServer set
    SERVERNAME=@SSASSERVERNAME,
    DESCRIPTION=@SSASDESCRIPTION,
ISDEFAULT = 1
WHERE SERVERNAME <> @SSASSERVERNAME -- Optional where clause if you want to see the "affected rows

---Set BCPRoxy Account---
update SYSBCPROXYUSERACCOUNT set SID=@BCPSID, NETWORKDOMAIN=@BCPDOMAIN, NETWORKALIAS= @BCPALIAS
where NETWORKALIAS != @BCPALIAS --optional to display affected rows.
---Set WF Execution Account---
update SYSWORKFLOWPARAMETERS set EXECUTIONUSERID=@WFEXECUTIONACCOUNT where EXECUTIONUSERID != @WFEXECUTIONACCOUNT
---Set Proj Sync Account---
update SYNCPARAMETERS set SYNCSERVICEUSER=@PROJSYNCACCOUNT where SyncServiceUser!= @PROJSYNCACCOUNT
---Set help server URL---
update SYSGLOBALCONFIGURATION set value=@helpserver where name='HelpServerLocation' and value != @helpserver

---Update Email Parameters---
Update SysEmailParameters set SMTPRELAYSERVERNAME = @SMTP_SERVER, @SMTP_PORT=@SMTP_PORT
---Update DMF Settings---
update DMFParameters set SHAREDFOLDERPATH = @DMFFolder
where SHAREDFOLDERPATH != @DMFFolder --Optional to see affected rows

---Set BCPRoxy Account---
update SYSBCPROXYUSERACCOUNT set SID=@BCPSID, NETWORKDOMAIN=@BCPDOMAIN, NETWORKALIAS= @BCPALIAS
where NETWORKALIAS != @BCPALIAS --optional to display affected rows.
---Set WF Execution Account---
update SYSWORKFLOWPARAMETERS set EXECUTIONUSERID=@WFEXECUTIONACCOUNT where EXECUTIONUSERID != @WFEXECUTIONACCOUNT
---Set Proj Sync Account---
update SYNCPARAMETERS set SYNCSERVICEUSER=@PROJSYNCACCOUNT where SyncServiceUser!= @PROJSYNCACCOUNT
---Set help server URL---
update SYSGLOBALCONFIGURATION set value=@helpserver where name='HelpServerLocation' and value != @helpserver

---Update Email Templates---
update SYSEMAILTABLE set SENDERADDR = @EMAIL_TEMPLATE_ADDRESS, SENDERNAME = @EMAIL_TEMPLATE_NAME where SENDERADDR!=@EMAIL_TEMPLATE_ADDRESS OR  SENDERNAME!=@EMAIL_TEMPLATE_NAME;
update SYSEMAILSYSTEMTABLE set SENDERADDR = @EMAIL_TEMPLATE_ADDRESS, SENDERNAME = @EMAIL_TEMPLATE_NAME where SENDERADDR!=@EMAIL_TEMPLATE_ADDRESS OR  SENDERNAME!=@EMAIL_TEMPLATE_NAME;
---Update User Email Addresses---
update sysuserinfo set sysuserinfo.EMAIL = '' where sysuserInfo.ID not in (select id from @ExclUserTable)

---Disable all users except for a specific set---
update userinfo set userinfo.enable=0 where  CharIndex('|'+ cast(ID as varchar) + '|' , @ENABLE_USERS) = 0
---Disable specific users---
---update userinfo set userinfo.enable=0 where  CharIndex('|'+ cast(ID as varchar) + '|' , @DISABLE_USERS) > 0

--Clean up server sessions
delete from SYSSERVERSESSIONS
--Clean up client sessions.
delete from SYSCLIENTSESSIONS

reference : http://www.exploreax.com/blog/blog/2015/10/13/ax-db-restore-scripts-full-script/

Thursday, May 14, 2015

How to delete Label Files from AX 2012

Here are the steps to delete Label Files from AX 2012:

  • Create a new model. You could call it "Test".
  • Open the AOT and move the Label File(s) you want to get rid of to the new model.
  • Close AX and stop the AOS.
  • Use AXUtil to delete the new model.
  • Select the label files (name start with 'ax' and followed with label id. select all files) and Delete from the server folder; C:\Program Files\Microsoft Dynamics AX\60\Server\...\bin\Application\Appl\Standard
  • Start the AOS.
  • Skip the upgrade wizard.

Friday, February 6, 2015

Read text file and SubStr to fetch fixed length columns - AX 2012

static void readTextFile(Args _args)
{
    Container               con;
    Filename                filename, Filename2;
    FileIOPermission        permission;
    TextIO                  textIO, textIO1;
    Str1260                 line;
    #File
    ;
    
    Filename = @"C:\Test\testFile.txt";
    permission = new fileIOpermission(filename,"RW");
    permission.assert();
    textIO = new TextIO(filename,#io_read);
    //textIO.inFieldDelimiter('|');
    if(textIO)
    {
        while(textIO.status() == IO_Status::Ok)
        {
            con = textIO.read();
            if(con)
            {
                line = Global::con2Str(con);
                info(strFmt("text - %1",line));
                info(strFmt("Company id - %1",subStr(line,1,4)));
                info(strFmt("code - %1",subStr(line,5,6)));
                info(strFmt("account num - %1",subStr(line,12,14)));
                info(strFmt("transdate - %1",subStr(line,26,6)));
                info(strFmt("Cheque num - %1",subStr(line,32,10)));
                info(strFmt("amount - %1",subStr(line,42,8)));
                break;
            }
        }
    }
}

Customer payment journal through X++ Code - AX 2012

static void cust_GLPosting(Args _args)
{
    Ledgerjournalname       ledgerjournalname;
    LedgerjournalTable      LedgerjournalTable;
    LedgerjournalTrans      LedgerjournalTrans;
    LedgerjournalCheckPost  LedgerjournalCheckPost;
    NumberSeq               numberSeq;
    Container               con;
    Filename                filename, Filename2;
    FileIOPermission        permission;
    TextIO                  textIO, textIO1;
    Dialog                  dialog;
    DialogField             dialogField;
    AccountNum              customerAccount= 'BRMF-000001';
    AccountNum              offsetAccNum = 'B01';
    #File

    select ledgerjournalname where ledgerjournalname.JournalName == "Test";
    ttsBegin;
    LedgerjournalTable.JournalName = ledgerjournalname.JournalName;
    LedgerjournalTable.initFromLedgerJournalName();
    LedgerjournalTable.JournalNum  = JournalTableData::newTable(LedgerjournalTable).nextJournalId();
    LedgerjournalTable.insert();
    ttsCommit;
        
    ttsBegin;
    numberSeq                               =   NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
    LedgerjournalTrans.Voucher              =   numberSeq.voucher();
    LedgerjournalTrans.JournalNum           =   LedgerjournalTable.JournalNum;
    LedgerjournalTrans.CurrencyCode         =   "USD";
    LedgerjournalTrans.ExchRate             =   Currency::exchRate(LedgerjournalTrans.CurrencyCode);
    LedgerjournalTrans.AccountType          =   LedgerJournalACType::Cust;
    LedgerjournalTrans.parmAccount(customerAccount,LedgerjournalTrans.AccountType);
    LedgerjournalTrans.Txt                  =   'Testing';//conPeek(con,1);
    LedgerjournalTrans.AmountCurCredit      =   200;//conPeek(con,3);
    LedgerjournalTrans.TransDate            =   systemDateGet();//str2Date(conPeek(con,4),123);
    LedgerjournalTrans.OffsetAccountType    =   LedgerJournalACType::Bank;//LedgerjournalTable.OffsetAccountType;
    //LedgerJournalTrans.offsetacco
    LedgerjournalTrans.OffsetLedgerDimension =   22565431567; //LedgerjournalTable.OffsetLedgerDimension;
    LedgerjournalTrans.DefaultDimension     =   CustTable::find(customerAccount).DefaultDimension;
    LedgerjournalTrans.OffsetDefaultDimension=  CustTable::find(customerAccount).DefaultDimension;
    LedgerjournalTrans.insert();
    ttsCommit;
               
    LedgerjournalCheckPost = LedgerjournalCheckPost::newLedgerJournalTable(LedgerjournalTable,NoYes::Yes);
    LedgerjournalCheckPost.run();
    
}

Tuesday, October 7, 2014

Create Menuitem at runtime or through X++ and set properties

Hi Guys,

Here is the example of creating menuitem through X++ code.


static void CreatingMenuItemRutime(Args _args)
{
    
    TreeNode          treeMenuItem;
    str                    menuName = "TestOutputMenuItem";
    str                    properties;
    #AOT
    #Properties
    ;
    
    treeMenuItem = TreeNode::findNode(#MenuItemsOutputPath);
    treeMenuItem.AOTadd(menuName);
    
    treeMenuItem = treeMenuItem.AOTfindChild(menuName);
    properties = treeMenuItem.AOTgetProperties();
    
    properties = setProperty( properties, #PropertyLabel,'Sales Report');
    properties = setProperty( properties, #PropertyObjectType, 'Class');
    properties = setProperty( properties, #PropertyObject,'SalesFormLetter');
    properties = setProperty( properties, #PropertyParameters, 'ReportX1\\Report');
    
    treeMenuItem.AOTsetProperties(properties);
    
    treeMenuItem.AOTsave();
    print "New Menuitem is created under output menuitem";
    pause;
}

Thursday, January 23, 2014

How to: Connect to an External Database from X++ Code [AX 2012] [AX 2009]

Create a DSN


To create a Data Source Name (DSN) go to Administrative Tools > Data Sources (ODBC).
Create the DSN on the tier where the X++ code will call the DSN from. This will be either on the client computer or on the Application Object Server (AOS) computer.
NoteNote
Ongoing maintenance is simpler if the DSN is created on the AOS tier.
X++ Code Example with ODBC


The following X++ code example uses ODBC to connect to an external database. The code example assumes that you have already created the DSN in Windows.
// X++, Main method in a class.
static public void Main(Args _args)
{
    LoginProperty loginProperty;
    OdbcConnection odbcConnection;
    Statement statement;
    ResultSet resultSet;
    str sql, criteria;
    SqlStatementExecutePermission perm;
    ;

    // Set the information on the ODBC.
    loginProperty = new LoginProperty();
    loginProperty.setDSN("dsnName");
    loginProperty.setDatabase("databaseName");

    //Create a connection to external database.
    odbcConnection = new OdbcConnection(loginProperty);

    if (odbcConnection)
    {
        sql = "SELECT * FROM MYTABLE WHERE FIELD = "
            + criteria
            + " ORDER BY FIELD1, FIELD2 ASC ;";

        //Assert permission for executing the sql string.
        perm = new SqlStatementExecutePermission(sql);
        perm.assert();

        //Prepare the sql statement.
        statement = odbcConnection.createStatement();
        resultSet = statement.executeQuery(sql);

        //Cause the sql statement to run,
        //then loop through each row in the result.
        while (resultSet.next())
        {
            //It is not possible to get field 3 and then 1.
            //Always get fields in numerical order, such as 1 then 2 the 3 etc.
            print resultSet.getString(1);
            print resultSet.getString(3);
        }

        //Close the connection.
        resultSet.close();
        statement.close();
    }
    else
    {
        error("Failed to log on to the database through ODBC.");
    }
}

32 Bit and 64 Bit Windows Operating System

The preceding code example can run on either the client tier or the server tier. The following table shows how the operating system architecture affects the choice of tier.

32 bit Windows
64 bit Windows
Client tier (MorphX)
Runnable.
Not runnable.
Server tier (AOS)
Runnable.
Runnable.
Consider adding the server keyword to the declaration of the Main method.
If you want to do Insert/Update operation through this code then you must use following code.

int      _returnId;

sql = " Your insert / Update Query"
 //Prepare the sql statement.
statement = odbcConnection.createStatement();
_returnId = statement.executeUpdate(sql);

reference :1. Microsoft Documentation MSDN 2. ArtofCreation 3. GalaxyofDynamics


Thursday, December 5, 2013

Enable/Disable Fact boxes, Preview Panes in AX2012 UX

In Microsoft Dynamics AX 2012, if you want to disable factboxes/preview panes across application then you can do so.
It's not recommended to do this activity but this will help in troubleshooting performance issues assoicated with opening forms in ax2012 by controlling 'Timeout' parameter as below.

Go to ->System Administration->Setup->Client performance options 

Visit  Ax2012-client-performance-options for detailed explaination by Ax performance team.

Thanks axperf team :)

reference from : http://learnax.blogspot.in/2012/02/enabledisable-fact-boxes-preview-panes.html

Monday, September 2, 2013

Working with SSRS reports in Dynamics AX 2012

Microsoft Dynamics AX provides a model-based approach for creating reports by providing project templates and modeling tools that are incorporated into the Microsoft Visual Studio development environment. The reporting features provided by Microsoft Dynamics AX are tightly integrated with SQL Server Reporting Services.
Reporting Services is a server-based reporting platform that provides comprehensive reporting functionality for a variety of data sources. The reporting framework includes a set of tools for you to define reports in the Microsoft Visual Studio development environment. The report development experience takes advantage of extended SQL Server tools and components fully integrated into the Microsoft Visual Studio environment. By using the reporting APIs, you can integrate or extend data and report processing in custom applications. The following table provides links to more information on these Microsoft technologies:
You can refere following url for more information about report development with SSRS,Dynamics AX 2012. 

Setting SysEntryPointAttribute for Services [AX 2012]

The SysEntryPointAttribute indicates what authorization checks are performed for a method that is called on the server. This attribute must be set for all service operations. For more information about how to set attributes on X++ methods, see Syntax for Attribute Classes.
The AIF Document Service Wizard automatically decorates service operations with [SysEntryPointAttribute(true)]. When you develop custom services you must use theSysEntryPointAttribute to decorate each service operation.
Setting :
The following table describes the possible values for the constructor of the SysEntryPointAttribute class.
[SysEntryPointAttribute(true)] - Indicates authorization checks are performed on the calling user for all tables accessed by the method.

[SysEntryPointAttribute(false)] - Indicates authorization checks are not performed on any tables accessed by the method.

Example :
[AifDocumentCreateAttribute, SysEntryPointAttribute(true)]
public AifEntityKeyList create(CustCustomer _custCustomer)
{
    return this.createList(_custCustomer);
}

reference : http://technet.microsoft.com/en-us/library/hh801193.aspx

Thursday, August 22, 2013

WINAPI functions and their use

Like most AX developers I use the WINAPI class quite often. Its a very useful class when handling files that need to be accessed outside of the AX environment

  static void FO_WinApi(Args _args)
  {
      str     root        = "C:";
      str     path        = "C:\\dionne";
      str     fileName    = "SalesInvoice.pdf";
      str     fileName2   = "SalesInvoice1.pdf";
      str     file        = path + "\\" + fileName;
      str     file2       = path + "\\" + fileName2;
      int     x, y;
      ;

      // Does folder exist?
      print WinAPI::folderExists(path);

      // Does file exist?
      print WinAPI::fileExists(file);

      // Copy file.
      print WinAPI::copyFile(file,file2);

      // New file exists?
      print WinAPI::fileExists(file2);

      // Delete new file.
      print WinAPI::deleteFile(file2);

      // New file still there?
      print WinAPI::fileExists(file2);

      // Get current cursor position.
      [x, y] = WinAPI::getCursorPos();

      print x;
      print y;

      // Get time and date format.
      print WinAPI::getSystemLocaleDateStr();
      print WinAPI::getSystemLocaleTimeStr();

      // Gets current computer name.
      print WinAPI::getComputerName();

      // Gets total disk space.
      print int2str(WinAPI::getDiskTotalSpaceInKb(root)
             / 1000) + " MB";

      // Gets current free space on disk.
      print int2str(WinAPI::getDiskFreeSpaceInKb(root)
             / 1000) + " MB";

      // Date when file was last accessed.
      print WinAPI::getFileAccessedDate(file);

      // Time when file was last accessed(In seconds).
      print WinAPI::getFileAccessedTime(file);

      // Gets path to temp directory.
      print WinAPI::getTempPath();

      // Gets a generated temporary filename, prefix "FO_".
      print WinAPI::getTempFilename(path, "FO_");

      pause;

  }
In addition to file information the WINAPI class can execute different file types from within Dynamics AX by of course using the file name as a parameter.
For example lets say you want to launch a PDF file saved in table within AX. WinAPI::ShellExecute() will do this for you.
- See more at: http://www.winfosoft.com/blog/microsoft-dynamics-ax/the-winapi-class#sthash.3QzP3keO.dpuf


reference from :http://www.winfosoft.com/blog/microsoft-dynamics-ax/the-winapi-class

Friday, July 19, 2013

How can I see the SQL query that the Dynamics AX Kernel is generating for my Form?

When you are debugging your solution you sometimes might want to see the SQL Query the Dynamics AX Kernel has generated for your Form. 
While you can of course trace this directly at your Database Server, you also can do this in X++ using the QueryBuildDataSource class.

Let's imagine you have a Form that has PurchTable as Data Source. You have to override the executeQuery method of the PurchTable Data Source and add the following code:

public void executeQuery()
{
   Query q;
   QueryBuildDataSource qbds;
   ;
   q = this.query();
   qbds = q.dataSourceName("PurchTable"); //Replace with the                                                 current Table
   info( qbds.toString() );

   super();
}

Monday, January 14, 2013

Set not empty / not blank record in query (AX 2009)

Hi,

If we want to set not empty condition at query then following code can be used in value

SysQuery::valueNotEmptyString()

Example:

this.query().dataSourceTable(tablenum(LedgerTrans)).addRange(fieldId2Ext(fieldnum(LedgerTrans, Dimension),5)).value(SysQuery::valueNotEmptyString());

Thursday, January 10, 2013

Most commonly used Format and code while creating reports X++ report


Most commonly used  Format and code while creating reports.



public class ReportRun extends ObjectRun
{
    TransDate               fromDate;
    TransDate               toDate;
    DialogField             dialogFromDate, dialogToDate;
    DialogField             dialogLedgerAccount;
    DialogField             dialogPrintExcelReport;
    LedgerAccount           ledgerAccount;

    LedgerTrans             ledgerTrans1, ledgerTransOpenBal;
    str 50                  dimension;
    AmountMST               amount;
    AmountCur               creditAmt,debitAmt;
    AmountCur               openingBalAmt,closingBalAmt;

    #define.CurrentVersion(4)
    #localmacro.CurrentList
        FromDate,
        ToDate,
        ledgerAccount
    #endmacro
}

==================================================


public container pack()
{
    return [#CurrentVersion,#CurrentList];
}

==================================================


public boolean unpack(container _packedClass)
{
    boolean     ret;
    Version     version = RunBase::getVersion(_packedClass);
    ;

    switch (version)
    {
        case #CurrentVersion:
            [version, #CurrentList] = _packedClass;
            ret = true;
            break;

        default :
            ret = false;
    }
    return ret;
}





==================================================


public Object dialog(Object _dialog)
{
    DialogRunbase dialog = _dialog;
    ;

    dialog.addGroup("Date Range");
    dialogFromDate = dialog.addFieldValue(typeid(TransDate), fromDate,"From Date");
    dialogToDate = dialog.addFieldValue(typeid(TransDate), toDate,"To Date");
    dialogLedgerAccount = dialog.addFieldValue(typeid(AccCategory), ledgerAccount,"Ledger Account");

    return dialog;
}


==================================================


public boolean getFromDialog()
{
    ;
    fromDate = dialogFromDate.value();
    toDate   = dialogToDate.value();
    ledgerAccount = dialogLedgerAccount.value();

    return true;
}



==================================================
Fetch method --------

queryRun = new QueryRun(this);
    this.query().dataSourceTable(tablenum(LedgerTrans)).addRange(fieldnum(LedgerTrans,TransDate)).value(queryrange(fromdate,todate));

this.query().dataSourceTable(tablenum(LedgerTrans)).addRange(fieldnum(LedgerTrans,AccountNum)).value(ledgerAccount);
    this.query().dataSourceTable(tablenum(LedgerTrans)).addOrderByField(fieldId2Ext(fieldnum(LedgerTrans, Dimension),5));

//this.query().dataSourceTable(tablenum(LedgerTrans)).orderMode(OrderMode::GroupBy);
    //this.query().dataSourceTable(tablenum(LedgerTrans)).addGroupByField(fieldId2Ext(fieldnum(LedgerTrans, Dimension),5));

//this.query().dataSourceTable(tablenum(LedgerTrans)).fields().addField(fieldnum(LedgerTrans, AmountCur), SelectionField::Sum);

//query.dataSourceNo(1).fields().addField(fieldnum(CustSettlement, SettleAmountMST), SelectionField::Sum);
    //this.query().dataSourceTable(tablenum(LedgerTrans)).addRange(fieldnum(LedgerTrans,Dimension[5])).value(dimension);

//this.query().dataSourceTable(tablenum(LedgerTrans)).addRange(fieldId2Ext(fieldnum(LedgerTrans, Dimension),5)).value("Anil P Talla");

//query.dataSourceNo(2).addGroupByField(fieldId2Ext(fieldnum(CustTrans, Dimension),1));



while (queryRun.next())
    {

        ledgerTrans = queryRun.get(tablenum(LedgerTrans));
        // Add code here
    }

Thursday, December 6, 2012

Add User to admin group from SQL / back end In AX 2009



Hi All,

When your user is not having any permissions to make changes in AX and you are unable to change the permission from ax then u can try to change the user group of that user from SQL studio manager i.e. back end.

Select the database on which you have to make changes.
check the user id and information with the following queries.

Select * from USERGROUPINFO

Select * from USERGROUPLIST 
(check which is the group assigned to your user and which you need)


Here i know that the usergroup ADMIN is having all the rights so i'm adding my user to admin group

Update USERGROUPLIST set GROUPID='Admin' where USERID='Kishr'

Friday, November 30, 2012

Report with Sum at Header using Duplicated Query


Your report needs the summation of some fields at the Header portion but you do not want to hack the report classes to achieve that.
Dynamics Ax subtotal is available only at the footer. If you need it in some other section, you would have to find a way around. We will look at an approach where the report query is duplicated for the necessary calculation at the section header.
The demo subsequently will produce the report illustrated in the following figure. The section footer is the subtotal produced by the standard report. The section header on the other hand shows the output of the approach suggested.
Dynamics Ax Report with Sum at Header

Motivation

There are ways to achieve this. The use of duplicated query is motivated by the following factors.
  • It could be applied to existing report without affecting the overall structure. In other words, no changes will be required on the data source and other sections in the report.
  • The calculation is in accordance to the filters set by the user without additional work.
  • The report query will be handled by Dynamics Ax report subsystem while we will only work on the duplicated copy of the query.

Technique Highlight

Basically we will have two copy of the same query. At the section group header, we will loop the duplicated copy until the next header group is reached. The necessary work is performed while we loop and the value to be shown at the group heading is prepared prior to executing the group header. Then the report subsystem will take over and loop the original copy of the query.
The following code segment illustrates the technique explained above.
// loop as long as within the same subheading group.
do {
  custTransLoop = qrHead.get(custTransLoop.TableId);
  if (custTransLoop.AccountNum == CustTrans.AccountNum) {
    rSum += custTransLoop.AmountCur;
  }
  else {
    break//heading group changed.
  }
while (qrHead.next());

mrSum = rSum; //value prepared for heading.

super(); //execute group heading.

The following code segment illustrates how the report query is duplicated into a QueryRun object.
qrHead = new QueryRun(element.query());

Demo

We will create a simple report with CustTrans as the only data source to demonstrate the highlighted approach. We dissect the whole process into three sections. The first will cover creating report while the second is regarding adding subtotal just to verify the outcome of the calculation. The final section is the one that cover the approach recommended. Those that are well versed with Dynamics Ax reporting tool may opt to skip the first two sections.

Create Report

The following steps cover report creation. Alternatively, you may use the Report Wizard to perform this.
  1. Create a new project to group objects if you have not.
  2. Right click on your project and select New > Report. You will have a report with the name Report1 created.
  3. Right click on Data Sources > Query > Data Sources and select New Data Source. Change the Table to CustTrans under the Property Page.
  4. Expand the node CustTrans(CustTrans) and right click on the node Sorting. Select New > Field. Ensure the Field is AccountNum. Change the properties AutoHeader and AutoSum to Yes.
  5. Right click on the Designs node and select New Report Design. You will see a new node named ReportDesign1 with a child node named AutoDesignSpecs.
  6. Right click on ReportDesign1 and select Generate Design. You will see a node named Generated Design added. You will also see a node named Section Group: CustTrans too.
  7. Expand the Section Group: CustTrans and right click on Body:CustTrans_Body. Select New Control > Field Group from CustTrans. Change the field group's DataGroup property to AutoReport.

Validation preparation

The following steps add a subtotal to a field for verification.
  1. Change the AutoFieldGroupOrder property to "Save the fields' properties" for the field group.
  2. Expand the Group and find control named Real: CustTrans_AmountCur and change the SumAll property to Yes.
  3. Right click on Footer: CustTrans_Footer and select New Control > Sum. Change the properties of the newly added for Table to CustTrans and Field to AmountCur.

Sum at Header

You now have a report with subheading. The following steps demonstrate the approach mentioned earlier.
  1. Add the following declaration to classDeclaration of the report. The classDeclaration will now look like the following.
  2. public class ReportRun extends ObjectRun
    {
      AmountCurDebCred  mrSum;
      QueryRun          qrHead;
    }

  3. Add a new method to Header: CustTrans_Header and copy the following code to it.
  4. display AmountCurDebCred SumAmtCur()
    {
      return mrSum;
    }

  5. Then add a new a control with the display method to the Header. This could be done by dragging the method and dropping it at the Header: CustTrans_Header node.
  6. Override the method executeSection() of the header with the following code. The method CustTrans_Header:executeSection() shall looks like the following.
  7. public void executeSection()
    {
      CustTrans  custTransLoop;
      real       rSum;

      // dupplicate the query on first execution of the header.
      if (!qrHead) {
        qrHead = new QueryRun(element.query());
        qrHead.next();
      }

      // loop as long as within the same subheading group.
      do {
        custTransLoop = qrHead.get(custTransLoop.TableId);
        if (custTransLoop.AccountNum == CustTrans.AccountNum) {
          rSum += custTransLoop.AmountCur;
        }
        else {
          break;
        }
      } while (qrHead.next());

      mrSum = rSum; //prepare value to be shown at group header.

      super(); //execute the group header.
    }


Source :http://axassociate.blogspot.in/search?updated-max=2008-03-20T14:28:00Z&max-results=3&start=9&by-date=false

Run External Application from Dynamics Ax


Calling up external program from Dynamics Ax can be something very interesting to audience during introductory training and demo. Once in a while, I will encounter associates asking if it is possible to run external program, open word document, open a URL in an external browser, etc. from within Dynamics Ax. Usually they will show a sign of immense enthusiasm when I show them how it is achieved. It is like their imagination is exploring all sort of creative ways to make use of this facility.
The interesting part is that executing external application is fairly effortless in Dynamics Ax. X++ is capable of calling Microsoft Windows Application Programming Interface (API). The common functionalities of the Win API have been built in classes WinAPIWinAPIServerWinGDI andWinInet. Running external application could be achieved through the static method WinAPI::shellExecute.

Static Method WinAPI::shellExecute

This method takes six parameters where five of them are optional parameters. The following code segment shows the interface of this method.
client static int shellExecute(
    Filename _lpFile,
    str      _lpParameters      = '',
    str      _lpDirectory       = '',
    str      _lpOperation       = #ShellExeOpen,
    int      _show              = #SW_SHOWNORMAL,
    boolean  _waitForCompletion = false
    )

The interface might look complicated but the first parameter is usually all we need to assign. It is sufficient to achieve most of the scenarios. The second parameter allows us to execute an executable with parameters. We will look at examples where this second parameter comes into play later.

Class SysShellExecute

The class SysShellExecute facilitates calling WinAPI::shellExecute. This class has a main method that call the method WinAPI::shellExecute using args.parm() as the first parameter. This enables WinAPI::shellExecute to be called from menu item with ease. This is important Dynamics Ax bring up windows through menu item. Menu item works with buttons with ease.
The following figure shows the property dialog of a menu item using SysShellExecute. The menu item shown will open an Internet Explorer browser when executed.
SysShellExecute Menu Item Property

Opening a File or URL

You shall not encounter any issue running application with class SysShellExecute. However, I have received enquiry when it comes to opening a file or a URL. I do not want to go into the ways they have tried. Basically opening file and URL are equally simple.

1. Default Application

Windows has associated different file type to a default application. We just need to execute the file name in order to open that file with the default application. The following figure shows the property page of a menu item that opens the website Dynamics Ax Associate in the default browser.
Open URL with SysShellExecute Menu Item

2. Specific Application

The previous approach opens the file or URL in the default application. There are cases where you need to specify the application to open the file with. You may achieve this with static method WinAPI::shellExecute.
Let say the default browser for your computer is FireFox and the website you are opening requires Internet Explorer. You may use the following code to open the URL with Internet Explorer.
WinAPI::shellExecute("IEXPLORE.EXE",
    "http://axassociate.blogspot.com");

Conclusion

The examples given above cover the execution of Windows Internet Explorer and opening of URL. They work similarly with a Word Document, Excel Spreadsheet, etc.

Source : http://axassociate.blogspot.in/2008/03/run-external-application-from-dynamics.html