My 2p about ERP Solutions, Information Worker Solutions and other software products (mainly Microsoft Dynamics AX and Microsoft SharePoint).

29 June 2010

Opening same form but with different behaviour

Business requirement: Change the behaviour of a form without user interaction

Upon opening a form, you would like to change its behaviour without interaction of the end user, for example, you want to preset some filters, hide some columns, … depending on the context it is called. Off course you want to avoid to create a second, third, … form for this requirement.

This post describes how this can be achived easily by merely creating a new Menu Item and adding a little piece of code in the form involved.

As example in this post the Project Item Requirements form will be opened with a different filter. Depending on the context, all item requirements will be shown or only the active requirements.

Solution: Use the EnumTypeParameter property on a Menu Item

  1. Drag and drop the ProjSalesItemReq form to the Display node in the AOT as such creating a new Display Menu Item.
  2. Set the EnumTypeParameter property of the newly created Menu Item to NoYes and the EnumParameter property to Yes.
  3. Add a variable to the init method of the form ProjSalesItemReq, which will be used to store the value according to with which menu item the ProjSalesItemReq form will be called.
    NoYes                   showAll;


  4. Add following code snippet to the init method of the form ProjSalesItemReq, to set the value of the filter if the form is called with the newly created Menu Item.
    …
    if (element.args().parmEnumType())

    {

        showAll = element.args().parmEnum();

        if (showAll)

        {

            ctrlActiveAll.selection(ProjActiveAll::All);

        }

    }
    …

  5. Add the newly created Menu Item to the ProjTable form.



If you open the Item Requirements form with the standard Dynamics AX MenuItemButton, the filter will be set to Active, showing only the active item requirements.





If you open the Item Requirements form with the newly created MenuItemButton, the filter will be set to All, showing all item requirements for the selected Project.





Continue reading......

by Patrik Luca 0 comments

25 June 2010

X++ Code Snippet: Using a Message Box

This X++ Code Snippet post describes the use of a Message Box to ask the user for a confirmation before an update or process is executed.

X++ Code Snippet: Using a Message Box

A Message Box will be created using the Box class, asking the end user for a confirmation before the process is executed. Create following job to understand the working of the Message Box. This job will do an update of the CustTable each time the end user presses the OK button in the Message Box, else the CustTable isn’t updated.

static void tutorial_box() 
{

    CustTable   custTable;
    ;


    if(Box::yesNo("Modify customer?"

                  , DialogButton::No)

        == DialogButton::No)
        return;


    ttsbegin;

    select forUpdate custTable

    where custTable.AccountNum  == "1101";


    custTable.Memo += "\r\n"
                   + date2str(SystemDateGet(),123,2,1,2,1,4)

+ " "

                   + time2str(timenow(), 1, 1);
    custTable.update();

    ttscommit;
}



Each time you run the Job a Message Box appears:





If the end user chooses Yes, the Memo field of the CustTable will be update, else not.



Continue reading......

by Patrik Luca 0 comments

15 June 2010

Export to Excel with X++ code: continued

Introduction

I wrote already in the past about the possibilities to export data from your Dynamics AX ERP system to Microsoft Excel through X++ code.

My first post Export to Excel with X++ code described how to export some data to different worksheets in an Excel file.

My second post Export to Excel with X++ code: the sequel described how to format the exported data in the Excel export file.

In this post I further elaborate about the formatting of data.

Use of the comObject method of the SysExcelStyle class

I already explained the use of the SysExcelStyle class in my previous posts. I created a Header style and set its font to bold and a specific color. These methods are easy to use, as they can found with the IntelliSense functionality.

However, by using the comObject method, you can go even further and have extra formatting possibilities at your disposal. Unfortunately, these can’t be found with IntelliSense, nor I find documentation about it. I found already these possibilities, if someone finds other ones, please post a comment: it could be handy for others aswell…


...
SysExcelStyle style;
;

...
// Set orientation
style.comObject().orientation(90);
// distribute text
style.horizontalalignment(-4117);
// center text
style.horizontalalignment(-4108);
// right align text
style.horizontalalignment(-4152);
// set indent level
style.comObject().indentlevel(5);
// wrap text
style.comObject().wraptext(true);
...


Continue reading......

by Patrik Luca 2 comments

31 May 2010

Links List May 2010

I decided to share all my interesting reads and resources month by month with my blog readers. You can find these posts by searching on the label Links. I'll try to order the resources in logical categories. If you would like to see some interesting stuff added in the next month, don't hesitate to post a comment.

So this is my Links post for May 2010.

Dynamics AX


Continue reading......

by Patrik Luca 0 comments

04 May 2010

Turning DataField Property off in a Section Group on a Report

Business Requirement

With the DataField Property of a section group control on a report, you can create sections using the same table. In this post I explain how you can turn this off if the DataField Property has a value in your Report Design.

This post uses an existing Report as example: Report CustGrossMarginByAccount. It can be found in Accounts Receivable > Reports > Statistics > Customer > Gross Margin by Customer.

Solution

Step 1 Add new global variables in the ClassDeclaration

Add new global variables dialogShowSubTotals and showSubTotals in the ClassDeclaration of Report CustGrossMarginByAccount: a new checkbox should become available on the startup dialog of the Report in which the end user can choose to print subtotals or not.

public class ReportRun extends ObjectRun

{

    Amount custGross;

    Amount custMargin;

    Amount custCost;

    Amount totGross;

    Amount totMargin;


    ReportSectionGroup      rsSG;

    ReportSection           rsBody;

    ReportSection           rsDetailHeader;

    ReportSection           rsSummaryHeader;

    CustName custName;


    DialogField         dialogSummary;

    NoYes               summary;

    DialogField         dialogShowSubTotals;

    NoYes               showSubTotals;


    #define.CurrentVersion(2)

    #localmacro.CurrentList

        summary,

        showSubTotals

    #endmacro

}



Step 2 Add a field to the dialog to have the option to print subtotals



Add a field to the dialog by modifying the dialog method: the user will be able to choose here if subtotals should be printed or not.



public Object dialog(Object _dialog)

{

    DialogRunbase dialog = super(_dialog);

    ;


    dialog.addGroup("@SYS7764");    // Parameters


    dialogSummary = dialog.addFieldValue(typeid(NoYes),
summary,
"@SYS62602",
"@SYS99221");


 

dialogShowSubTotals = dialog.addFieldValue(typeid(NoYes),
showSubTotals,
"@SYS26674");


    return dialog;
}




Step 3 Store the value by modifying the getFromDialog method



Modify the getFromDialog method to store the value of the chosen print option.



public NoYes getFromDialog()

{

    ;

    summary = dialogSummary.value();
    showSubTotals = dialogShowSubTotals.value();

    return true;

}



Step 4 Modify the fetch method to turn subtotals on or off



Modify the fetch method to switch the subtotals on or off.



public boolean fetch()

{
Queryrun qr;

    ReportSectionGroup  reportSectionGroup;

    ;

    if (!showSubTotals)

    {

        reportSectionGroup = element.design().sectionGroup( tableNum(CustInvoiceJour)

            ,fieldName2Id(tableNum(CustInvoiceJour)

            ,"OrderAccount"));

        reportSectionGroup.dataField(0);

    } …..

}


Result



Upon starting the Report CustGrossMarginByAccount the end user has the option to print the subtotals per Order Account or not.





Leaving the option unchecked, results in a report without subtotals per Order Account:





Checking the subtotals option results in a report with the subtotals:





Continue reading......

by Patrik Luca 0 comments

30 April 2010

Links List April 2010

I decided to share all my interesting reads and resources month by month with my blog readers. You can find these posts by searching on the label Links. I'll try to order the resources in logical categories. If you would like to see some interesting stuff added in the next month, don't hesitate to post a comment.

So this is my Links post for April 2010.

Dynamics AX


Continue reading......

by Patrik Luca 0 comments

14 April 2010

Export to Excel with X++ code: the sequel

Introduction

This post is a sequel to my post Export to Excel with X++ code. In this post I add some formatting to my Excel export file.

  • autofit column width
  • working with styles to set fonts to bold
  • working with style to set font color
  • setting the format of a column

X++ code

Add following extra variables in the beginning of the job:

SysExcelStyles                  styles;
SysExcelStyle                   style;
SysExcelFont                    font;
SysExcelCells cells;

After having created the workbook, create a new style as follows:


styles = sysExcelWorkBook.styles(); 
// Create new style
style = styles.add('Header');
// Set font for this style to bold
font = style.font();
font.bold(true);
font.color(255);

Right after having created the title row on the first worksheet, set its style to our created Header style.


// Set the title row in the Header style
sysExcelWorksheet.rows().item(1).style('Header');

For each added worksheet with backorder lines, set the style of the title row also to our created Header style.


// Set the title row in the Header style
sysExcelWorksheetBackOrder.rows().item(1).style('Header');

Set the column width to autofit for the first worksheet.


// Set the column width to autofit
sysExcelWorksheet.columns().autoFit();

Set the column width to autofit for each added worksheet with backorder lines. Make sure you do this after you have added all rows in the worksheet, so it can take into account the width of the largest value in your column.


// Set the column width to autofit
sysExcelWorksheetBackOrder.columns().autoFit();

Format the fourth column (Deliver Remainder) for each added worksheet with backorder lines as a Number with two decimal places.


// Format the 4th column to a Number with 2 decimal places
cells = sysExcelWorksheetBackOrder.cells();
cells.range('D2:D99').numberFormat("0,00");

The complete job looks then like this:




static void ExportToExcel(Args _args)
{
#AviFiles
SysOperationProgress progress = new SysOperationProgress();
SysExcelApplication sysExcelApplication;
SysExcelWorkbooks sysExcelWorkBooks;
// Filename to which you will be writing your data
FileName fileName = "C:\\Windows\\Temp\\ExportToExcel.xlsx";
SysExcelWorkbook sysExcelWorkBook;
SysExcelWorkSheets sysExcelWorkSheets;
SysExcelWorkSheet sysExcelWorkSheet;
SysExcelWorkSheet sysExcelWorksheetBackOrder;
SysExcelWorksheet sysExcelWorkSheetToBeDeleted;
SysExcelStyles styles;
SysExcelStyle style;
SysExcelFont font;
SysExcelCells cells;
int row = 1;
int rowBackOrder;
CustTable custTable;
SalesTable salesTable;
SalesLine salesLine;
boolean workSheetAdded = false;
int nbrOfCustomers;
;

// Initialising progress bar
progress.setCaption("Export To Excel in progress...");
progress.setAnimation(#AviTransfer);
// Initialisation of some objects
sysExcelApplication = SysExcelApplication::construct();
// Create new workbook
sysExcelWorkBooks = sysExcelApplication.workbooks();
sysExcelWorkBook = sysExcelWorkBooks.add();
// Create new style
styles = sysExcelWorkBook.styles();
style = styles.add("Header");
// Set font for this style to bold and color to red
font = style.font();
font.bold(true);
font.color(255);
// Get worksheets collection
sysExcelWorkSheets = sysExcelWorkbook.worksheets();
// Excel visible on desktop running the job or not?
sysExcelApplication.visible(false);
// Newly created Excel files have by default some worksheets
// Delete those worksheets created by default
while(sysExcelWorkSheets.count() > 1)
{
sysExcelWorkSheetToBeDeleted = sysExcelWorkSheets.itemFromNum(2);
sysExcelWorkSheetToBeDeleted.delete();
}
// Add as many worksheets as there are customers
select count(RecId) from CustTable;
sysExcelWorkSheet = sysExcelWorkSheets.add(null,null,CustTable.RecId);
// Add another worksheet
sysExcelWorkSheet = sysExcelWorkSheets.add();
//Rename the first worksheet
sysExcelWorkSheet.name("Customers");
// Make a title row
// set a value in cell on row 1 column 1
sysExcelWorkSheet.cells().item(1,1).value("Customer account");
// set a value in cell on row 1 column 2
sysExcelWorksheet.cells().item(1,2).value("Name");
// set the title row in the Header style
sysExcelWorksheet.rows().item(1).style("Header");
while select custTable
{
progress.setText(strfmt("Customer %1", custTable.Name));
row++;
rowBackOrder = 1;
sysExcelWorksheet.cells().item(row,1).value(custTable.AccountNum);
sysExcelWorksheet.cells().item(row,2).value(custTable.Name);
while select salesLine
where salesLine.SalesStatus == salesStatus::Backorder
&& salesLine.ConfirmedDlv < Today()
&& salesLine.RemainSalesPhysical > 0
join salesTable
where salesTable.SalesId == salesLine.SalesId &&
salesTable.CustAccount == custTable.AccountNum
{
if(!workSheetAdded)
{
// Use the next Excel worksheet and rename it
sysExcelWorksheetBackOrder = sysExcelWorkSheets.itemFromNum(
row);
//Name of worksheet can have maximum 31 characters
sysExcelWorksheetBackOrder.name(substr(custTable.Name,1,31));
workSheetAdded = true;
// Make a title row
// set a value in cell on row 1 column 1
sysExcelWorksheetBackOrder.cells().item(1,1).value(
"Ship Date");
// set a value in cell on row 1 column 2
sysExcelWorksheetBackOrder.cells().item(1,2).value(
"Item Number");
// set a value in cell on row 1 column 3
sysExcelWorksheetBackOrder.cells().item(1,3).value(
"Item Name");
// set a value in cell on row 1 column 4
sysExcelWorksheetBackOrder.cells().item(1,4).value(
"Deliver Remainder");
// set the title row in the Header style
sysExcelWorksheetBackOrder.rows().item(1).style("Header");
}
rowBackOrder++;
sysExcelWorksheetBackOrder.cells().item(rowBackOrder,1).value(
salesLine.ConfirmedDlv);
sysExcelWorksheetBackOrder.cells().item(rowBackOrder,2).value(
salesLine.ItemId);
sysExcelWorksheetBackOrder.cells().item(rowBackOrder,3).value(
InventTable::find(salesLine.ItemId).ItemName);
sysExcelWorksheetBackOrder.cells().item(rowBackOrder,4).value(
salesLine.RemainSalesPhysical);
}
// Set the column width to autofit
sysExcelWorksheetBackOrder.columns().autoFit();
// Format the 4th column as Number with 2 decimal places
cells = sysExcelWorksheetBackOrder.cells();
cells.range("D2:D99").numberFormat("0,00");
workSheetAdded = false;
}
// Set the column width to autoFit
sysExcelWorksheet.columns().autoFit();
// Suppress the pop-up window:
// A file named foo already exists in this location. Do you want to replace it?
sysExcelApplication.displayAlerts(false);
// Save the Excel file
sysExcelWorkbook.saveAs(fileName);
sysExcelWorkBook.comObject().save();
sysExcelWorkBook.saved(true);
// Make sure you close the Excel application
// Especially if you run the job without showing Excel on the desktop
// (sysExcelApplication.visible(false))
sysExcelApplication.quit();

}



The result should look like this if you execute the job on the demo data in Microsoft Dynamics AX 2009 with Microsoft Excel 2007:





This is the first worksheet in my Excel workbook with the complete list of my customers in it.





This is one of the other worksheets, being the one created for customer Forest Wholesales and showing all the backorder lines for this particular customer.



Continue reading......

by Patrik Luca 21 comments

Patrik Luca, Ieper, BELGIUM
Feel free to use or spread all of the content on my blog. In return, linking back to my blog would be greatly appreciated. All my posts and articles are provided "AS IS" with no warranties.

Subscribe feeds via e-mail
Subscribe in your preferred RSS reader

Subscribe feeds rss Most Read Entries

Categories

Recommended Books


Subscribe feeds rss Recent Comments

This Blog is part of the U Comment I Follow movement in blogosphere. Means the comment field of this blog is made DOFOLLOW. Spam wont be tolerated.

Blog Archive

My Blog List

Followers

Links