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

19 October 2010

X++ Code Snippet: handle all values in a conditional statement

This X++ Code Snippet describes how to handle all values in a switch statement or if else statement. If you want to avoid someone calls the function or method with a value which isn’t explicitly handled in your conditional statement, you can throw an error with the name of the function to the end user, making the end user aware of the fact that an unexpected value is used in the written code.

For a switch statement you add the default section as follows:

switch (_variable)
{
case value1:
some code;
break;
case value2:
some code;
break;
default:
throw error(strFmt("@SYS23396",funcName()));
}

For an if else statement:


if (value1)
{
some code;
}
else
{
throw error(strFmt("@SYS23396",funcName()));
}


Continue reading......

by Patrik Luca 0 comments

30 September 2010

Links List September 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 September 2010.

Dynamics AX

Blogging – Blogging Tips

Freeware

  • MyPhoneExplorer: Connect your phone via cable, bluetooth or infrared with this software (direct sync to Outlook). My Sony Ericsson phone didn’t synchronise anymore with Outlook 2010 with the Sony software: this software made the synchronisation possible again.


Continue reading......

by Patrik Luca 0 comments

24 September 2010

X++ Code Snippet: Find available quantity from the physical inventory over all storage dimensions

This X++ Code Snippet post describes how to find the available quantity from the physical inventory over all storage dimensions (it is, without taking into account site, warehouse, batch number, location, pallet id or serial number) for a particular item.

X++ Code Snippet: Find available quantity from the physical inventory over all storage dimensions

display InventQtyAvailPhysical inventQtyAvailPhysical(
ItemId _itemId)
{
InventOnHand inventOnHand = new InventOnHand();
InventDimParm inventDimParm;
;

inventDimParm.initFromInventDim(
InventDim::findOrCreatedBlank());
inventOnHand.parmInventDimParm(inventDimParm);

inventOnHand.parmItemId(_itemId);
return inventOnHand.availPhysical();
}


Continue reading......

by Patrik Luca 0 comments

19 July 2010

Add Supplementary items functionality to Project Item Requirements

Business Requirement: Supplementary items functionality on Project Item Requirements

In standard Dynamics AX, the Supplementary Items functionality to calculate the number of supplementary items to be added to an order line is not available for item requirements. It can be added however easily to Project Item Requirements.

Solution: add the Supplementary Items functionality to Project Item Requirements

  1. Add a new MenuItemButton to the MenuButton control ButtonLinePriceCalc on the ProjSalesItemReq form.
  2. Set following properties on the newly added control:
    MenuItemType: Action
    MenuItemName: SuppItemCalc_Sales
    DataSource: SalesTable
  3. Override the clicked method of the newly added control and add following code:
    void clicked()

    {
        Args        _args = new Args();
        ;


        _args.record(SalesTable::find(salesLine.SalesId));
        SuppItemCreate::main(_args);

        salesLine_ds.reread();

        salesLine_ds.refresh();

        salesLine_ds.executeQuery();

    }





Do the necessary setup of a trade agreement of the supplementary items kind for a specific item. Add an item requirement for that item. Execute the Calculation of Supplementary Items: you’ll see the results according to your created trade agreement.


Continue reading......

by Patrik Luca 0 comments

17 July 2010

Add method of Styles class failed

Problem description: Add method of Styles class failed

Upon exporting some Dynamics AX data to Microsoft Excel, I ran into an Error, mentioning the cryptic Add method of Styles class failed.

Solution: Rename the added Style

I described in a previous post Export to Excel with X++ code: the sequel, how formatting can be added to the exported AX data in Excel by using the Styles class. This error message occurs when the collection object of the same class and name already exists, and you attempt to add it a second time with the same name. So apparently I had already a Style in my Microsoft Excel file with the same name as I was adding through my X++ code. I changed the name of my added Styles in my X++ code an my export went fine afterwards.


Continue reading......

by Patrik Luca 0 comments

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

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