jeudi 20 octobre 2011

How to copy records in a grid of a form

Here is an example of copying a record from a grid :
 In the clicked method of the button

public void clicked()
{
    super();
    ThyKanbanTable::createCopy(thyKanbanTable);
    thyKanbanTable_ds.executeQuery();
    thyKanbanTable_ds.last(); // set the cursor at the last record copied
    Tab.tab(1); // display the tab number one of the form
}
createCopy is declared under the ThyKanbanTable as following :

public static server void createCopy(ThyKanbanTable _ThyKanbanTable)
{
    ThyKanbanTable          newKanbanTable;

    ;

    ttsbegin;

    newKanbanTable.data(_ThyKanbanTable);
    newKanbanTable.KanbanID = NumberSeq::newGetNum(ThyKanbanParameters::numRefKanbanId()).num();
    newKanbanTable.insert();

    ttscommit;
}

mercredi 19 octobre 2011

What are the Add-ons for Microsoft Dynamics AX 2012


Microsoft Dynamics AX 2012 empowers people to anticipate and embrace change, enabling businesses to thrive.

Here are some docuements of Microssoft Dynamics AX 2012.

http://www.megaupload.com/?d=XTJUCZIP

http://www.megaupload.com/?d=QG6TBTFA 


mardi 11 octobre 2011

How to get rid of the report scaling message

When a report doesn't fit on a page, depending on it's properties Ax will resize the report. This is a powerful and very useful feature.
Now Ax will inform you that the report has been rescaled (Report is scaled xx percent to fit to page) and this message is generally not well received by users.


 Users are annoyed by the message, they get it every time they run the report, they cannot do anything about it, they have to click to close the infolog, ...

Ax has a builtin feature to suppress this scaling message. You can modify the init method of your report, and add something like this:

this.printJobSettings().suppressScalingMessage(true);

This is very effective and will do the job.
Only, this requires you to modify every report with these kind of messages.

A nicer way would be if we could switch it off in one place for all reports. Fortunately, this is possible as well.
Go to class SysReportRun, in the Run method, place following code before the call to super:

if(this.printJobSettings())
this.printJobSettings().suppressScalingMessage(true); 


void run(boolean onlyReport = false)
{
    // If this report is a webReport the run a webReport.
    if (webSession() && runBaseReport)
    {
        runBaseReport.runWebReport();
    }
    else
    {
        // When running the report and onlyReport = true then run the report.
        if (!onlyReport && runBaseReport)
        {
            if (runBaseReport.prompt())
            {
                runBaseReport.run();
            }
            // If the prompt returns false the do not run the report.
            // The RunBaseReport.Run method calls the ReportRun.run method with the parm onlyReport = true.
            return;
        }
    }

    this.buildPrintGrandTotal();
    this.buildPrintOnlyTotals();

    // <iba> 30 december 2010
    //scaling message suppressed by default
    if(this.printJobSettings())
        this.printJobSettings().suppressScalingMessage(true);
     // </iba> 30 december 2010

    super();
}


Now we don't have to modify each and every report and our users are happy.

Note that you can still override the settings in your report. In some reports this is done by default, like SalesInvoice and SalesConfirm.
 

How to go through records in a grid of a form

Sometimes, simply selecting the lines you want in a datasource and pressing OK (or other button) is not enough for the users. They want to clearly see what they have selected, be able to easily modify the selecting, and to their liking whould be to see a checkbox on the left of the grid for each line. (For an example, see CustTransOpen form where you mark transaction with a checkbox)
Here is a simple tutorial form based on InventTable datasource. You can select multiple lines and process the lines by pressing Process lines button. 

www.axaptapedia.com/images/c/c9/Tutorial_Form_MultiSelectCheckBox.zip

and here is an example to go through records in a grid using Maps:

// Changed on 07 Oct 2011 at 16:10:00 by iba
void clicked()
{
    MapEnumerator           me;
    WMSOrderTrans           WMSOrderTransCopy;
    ;

    me = Map::create(selectedLines.pack()).getEnumerator();

    ttsbegin;
    while (me.moveNext())
    {
        select firstOnly forupdate WMSOrderTransCopy
            where WMSOrderTransCopy.RecId == me.current();
            if(InventItemInventSetUp::findDefault(WMSOrderTransCopy.itemId).HighestQty != 0)
            {
                WMSOrderTransCopy.splitByDefaultQty(InventItemInventSetUp::findDefault(WMSOrderTransCopy.itemId).HighestQty);
            }
    }

    selectedLines = new Map(Types::Int64,Types::Container);
   
    WMSOrderTrans_ds.research();

 
    if (selectedLines.exists(wmsOrderTrans.RecId))
    {
        selectedLines.remove(wmsOrderTrans.RecId);
    }

    ttscommit;
 
    super();
}


lundi 10 octobre 2011

How to limit inserting records in a table

Here is an example of a method in a form for limiting the number of records to 12 :

void Query_cntRecords()
{
    Query                query = new Query();
    QueryRun             queryRun;
    QueryBuildDataSource qbd;
    ;

    qbd = query.addDataSource(tablenum(Thy_InventSymbolsIcons));
    queryRun = new QueryRun(query);

    if (SysQuery::countTotal(queryRun) == 13)
    {
        info(strfmt("@THY83"));
    }
}

How to insert/remove image in a table

If you need to import an image from your desktop to a table in dynamics AX, then you need a field which extendedDataType is bitmap and here is a code that you can write in the clicked method of your form

void clicked()
{
    FilenameFilter filter = ['Image Files','*.bmp;*.jpg;*.gif;*.jpeg'];
    BinData binData = new BinData();
    str extention, path, nameOfFile;
    super();

    imageFilePathName = WinAPI::getOpenFileName(element.hWnd(),filter,'', "@SYS53008", '','');
    if (imageFilePathname && WinAPI::fileExists(imageFilePathName))
    {
        [path, nameOfFile, extention] = fileNameSplit(imageFilePathName);
        if (extention == '.bmp' ||
            extention == '.jpg' ||
            extention == '.gif' ||
            extention == '.jpeg')
        {
            binData.loadFile(imageFilePathName);
            imageContainer = binData.getData();
            element.showLogo();
            Thy_InventSymbolsIcons.Image              = imageContainer;
        }
        else
        {
            throw error("@SYS89176");
        }
    }
    element.Query_cntRecords();
}

then if you want to remove an image :
void clicked()
{
    super();
    element.delete();
}


and the delete mehtod is defined as follows:
void delete()
{;
    Thy_InventSymbolsIcons.Image              = connull();
    Thy_InventSymbolsIcons_ds.refresh();
}


Here is the code  

http://www.megaupload.com/?d=88LTVWC1