Friday, January 20, 2012

Launch AOT forms & Reports without using Classfactory from x++


static void Args_report_Job15(Args _args)
{
    Args    args;
    ReportRun reportRun;
    ;
    args = new Args();
    args.name(reportstr(custtranslist));
    reportRun = new reportRun(args);
    reportRun.init();
    reportRun.run();
}

static void Args_form_Job15(Args _args)
{
    Args    args;
    FormRun formRun;
    ;
    args = new Args();
    args.name(formstr(custtable));
    formRun = new FormRun(args);
    formRun.init();
    formRun.run();
    formRun.detach();
}

Launch MenuItem from x++

you can call the menuitem itself using Menufunction.


Here is an example that should work.
static void Menuitem_job(Args _args)
{
MenuFunction mf;
;
mf = new menufunction(menuitemdisplaystr(CustTable), MenuItemType::Display);
mf.run();
}


Above code will open the CustTable From.

Thursday, January 12, 2012

How to Use a Programmable Section in Reports in Dynamics AX

We can use programmable sections to add any kind of customized information for example : sum of fields in the report . 

To activate a programmable section, activate it explicitly with anelement.execute(Number) statement. The Number must be specified in theControlNumber property for the design section.

For example, I've created a prgrammable section calculating the sum of a column in dynamics ax .
To call this section , I add the method element.execute(1); in the fetch method after calling super() and before returning the result of the fetch

public boolean fetch()
{
    boolean ret;  
    ret = super();
    element.execute(1);
    return ret;
}

How to get GrandTotal using autodesign report

Open Property window of Autodeign node in your report & set "yes" to Grandtotal Property--- this will print the total always!!

Friday, October 07, 2011

Batch Task Dependency in Dynamics AX 2009


Hello Friends,

Scenario : 
You want to schedule 2-3 tasks,  but you would like to define dependency among tasks.
Means Task1 should be executed only after completion of Task 3 and Task 2.


Advantage :
You all might have heard of "Divide and Conquer Rule", So this also implements the same.
Generally if you create batch to process 1000 Purchase orders then it might slow down the AOS performance and delay the overall batch performance.
But if you create batch and create 10 tasks, each process 100 Purchase orders then will be fast compared to above procedure and will improve overall batch performance.

How to :
In Dynamics AX 2009,  Batch process will make use of below tables
  •      BatchJob   : Main Job scheduler, consists of task
  •      BatchTask : Task in batch which specifies what class to execute in order to achieve    certain  functionality.
  •      BatchConstraint : Used to build dependencies among the tasks.

Create a Job, by using below code

static void Batch_CreateDependency(Args _args)
{
    BatchJob                batchJob;
    Batch                   batch;
    Tutorial_runBaseBatch   testDependency;
    BatchConstraints        batchConstraints;
    RefRecId                RecId_Task1, recId_task2, recId_task3;
    
    // Create task
    RefRecId createTask(str _msg)
    {
        ;
        batch.clear();
        batch.initValue();
        batch.GroupId           = '';
        batch.BatchJobId        = batchJob.RecId;
        batch.RunType           = BatchRunType::Server;
        batch.RetriesOnFailure  = 0;
        batch.AutomaticTransaction = NoYes::No;
        batch.Caption           = _msg;
        batch.Status            = BatchStatus::Waiting;
        batch.Company           = curext();
        testDependency          = Tutorial_runBaseBatch::construct();
        batch.ClassNumber       = classidget(testDependency);
        batch.insert();
        
        return batch.RecId;
    }
    
    // Building dependencies
    void buildDependency(RefRecId _batchId, RefRecid _dependendRecId)
    {
        ;
        batchConstraints.clear();
        batchConstraints.initValue();
        batchConstraints.BatchId = _batchId;
        batchConstraints.DependsOnBatchId = _dependendRecId;
        batchConstraints.ExpectedStatus = BatchDependencyStatus::FinishedOrError;
        batchConstraints.insert();
    }
    
    ;

    batchJob.clear();
    batchJob.initValue();
    batchJob.OrigStartDateTime = DateTimeUtil::newDateTime(systemDateGet(), DateTimeUtil::time(DateTimeUtil::utcNow()) + 10);
    batchJob.Status = BatchStatus::Waiting;
    batchJob.Caption = "Test Batch Dependency";
    batchJob.insert();

    recId_Task1 = createTask("Task 1");
    recId_Task2 = createTask("Task 2");
    recId_Task3 = createTask("Task 3");
    
    buildDependency(recId_Task1, recId_Task2);
    buildDependency(recId_Task1, recId_Task3);
    
    info(strfmt("The %1 Job scheduled to run 3 tasks", batchJob.Caption));
}

When you execute this Job, Go to Basic-->Inquiries-->Batch Job and you should see as below,

As per the snap, you can see Task 1 will be executed once Task 2 and Task 3 gets completed.

Enjoy Multi Threading  :)

Thursday, September 08, 2011

Connect to an External Database from X++ Code

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 AOS computer.

X++ Code Example with ODBC


// X++ job
static void TestOdbcJob()
{
    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.");
    }
}

Wednesday, September 07, 2011

Create a custom site theme for SharePoint and make it available to others


Here are the steps you can follow to create your own custom theme and make it available to others in your organization. For this example, I created a new theme called "My Custom Theme" based on the Classic theme in SharePoint.

1 - Identify a theme that closely resembles the theme you want to create

The first step is to first take a look at the existing themes available in SharePoint and determine if one of those themes closely resembles the theme that you want to create.
  1. Go to the SharePoint site where you want to create the theme (log on, if necessary).
  2. Click the Site Actions menu and choose Site Settings.
  3. Under Look and Feel, click Site theme.
  4. Look through the themes until you find one that closely resembles the theme you want to create. Note the name of the theme so you can find the files you need for later steps.
  5. For this example, I know that I want to use the Classic theme.
  6. Cancel out of the Site Theme page.
2- Create your custom theme folder
  1. Log onto the server that hosts your SharePoint site and browse to the following folder:
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\THEMES
  2. Copy the folder that corresponds with our theme. In my case, I copied the Classic folder.
  3. Paste this into this same THEMES folder, so that you end up with a Copy of THEMENAME folder. In my case, I ended up with a Copy of CLASSIC folder.
  4. Rename this folder to MyCustomTheme.
3 - Modify the theme setup information file (INF)
  1. Open the MyCustomTheme folder and locate the name of the theme you chose as a starting point for your new theme. For example, CLASSIC.INF.
  2. Rename CLASSIC.INF (or the INF file for the theme you chose) to MYCUSTOMTHEME.INF (yes, please use upper case).
  3. Edit MYCUSTOMTHEME.INF in Notepad (or your preferred text editor).
  4. Perform a search and replace in this file, replacing every instance of Classic (or the theme you chose) withMyCustomTheme.
  5. Save and close MYCUSTOMTHEME.INF.
4 - Modify the SPTHEMES.XML file
  1. Browse to the following folder:
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033
  2. Locate SPTHEMES.XML.
  3. Edit SPTHEMES.XML in Notepad (or your preferred text editor).
  4. Add the following text after the <SPThemes> tag so that it matches the other templates in this file:
    <Templates>
     <TemplateID>MyCustomTheme</TemplateID>
     <DisplayName>My Custom Theme</DisplayName>
     <Description>My Custom Theme.</Description>
     <Thumbnail>images/mycustomtheme.gif</Thumbnail>
     <Preview>images/mycustomtheme.gif</Preview>
    </Templates>
  5. Save and close SPTHEMES.XML.
  6. Reset the server so that your theme shows up on the Site Theme page in SharePoint. You can reset the server by entering the following text in the Start > RUN line:
    iisreset computer name
    (where computer name is the name of the server)
5 - Apply your custom theme to your site
  1. Return to your SharePoint site.
  2. Click the Site Actions menu and choose Site Settings.
  3. Under Look and Feel, click Site theme.
  4. In the list of themes, select My Custom Theme.
  5. Click Apply.
    Your site will look no different from the Classic theme since we based your custom theme on it. 

Delete caches in Dynamics 365 F&O

In Dynamics 365 Finance and Operations (D365 F&O), clearing the Application Object Tree (AOT) cache usually involves running specific ut...