Dynamics AX2012: Create Custom Service using X++

January 24, 2012 1 comment


Case Study: In this demo scenario, we create a custom service to find the inventory onhand physical item quantity from AX2012.

To expose any Custom Service, method should be ‘public’ Access Specifiers & should be defined by an attribute named ‘[SysEntryPointAttribute(true)]‘.



For this project, I have a created a sample InventoryOnHand service which basically returns the number of qty for a given Item.

class InventOnhandService
{
}

[SysEntryPointAttribute(true)]
public InventQty itemOnHandPhysical(ItemId  _itemId = '')
{
    SalesLine       salesLine;
    InventOnhand    inventOnHand;
    InventMovement  movement;
    InventQty       qty = 0;

    select firstOnly salesLine
        where salesLine.ItemId == _itemId;

    if (salesLine)
    {
        movement     = InventMovement::construct(salesLine);
        inventOnhand = InventOnhand::newPhysicalUpdate(movement,
                                                       movement.inventdim());

        qty          = inventOnHand.availPhysical();
    }

    return qty;
}


Next step is to create a ‘Service’ & map the custom class with newly created service. By which you could exposed all public methods which are in the scope of current class. Please proceed further by Creating a New Service Group & Add it to Service Node Reference. Please mark the ‘Auto Deploy’ property to ‘Yes’ on the Service group (properties).

Right click on the created Service group and click ‘Deploy Service Group’. This would deploy all the relavent artifacts to the Inbound port under System Administration module.


In order to test your custom Service application, simply start VS Command prompt (or) traverse through Start -> AllPrograms -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt

Enter wcftestclient, space and then paste the WSDL URI (which you can find on the deployed Inbound port)



When the WCF test client starts double click on your method ‘itemOnHandPhysical’(in my case) and specify the value under request by passing the _itemId (i.e. 1290 in my case) the invoke function will return the appropriate response of the available physical quantity of an item from the AX2012.



Download Link: InventoryOnHandService happy servicing AX2012 :)

My Blog Review in 2011

January 1, 2012 Leave a comment

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

The concert hall at the Syndey Opera House holds 2,700 people. This blog was viewed about 14,000 times in 2011. If it were a concert at Sydney Opera House, it would take about 5 sold-out performances for that many people to see it.

Click here to see the complete report.

Categories: Uncategorized

Dynamics AX2012: Table Full Text Indexes

September 26, 2011 Leave a comment

Microsoft Dynamics AX 2012 provides full-text functionality that enables Microsoft Dynamics AX to search business data over a large volume of text data or documents.


Please refer the following link which explains on the same.

http://dynamicsaxgyan.wordpress.com/2011/08/09/
full-text-index-in-dynamics-ax-2012-x/#comment-203/

Thanks Sreenath :) for the awesome article.

Also refer ‘AX Wonders’ blog which explains on setting up ‘Full Text Index’ Setup in SQL Server 2008 R2

http://axwonders.blogspot.com/2011/03/
sql-2008r2-full-text-index-search-setup.html/"



Example:

/*
   Two important rules for creating Full Text Indexes

[Technet]
TableGroup property.
    A table can have a full text index only if the TableGroup property
    is set to Main or Group on the table.

    A full text index can only be created on a table with RecId index.
    So make sure 'CreateRecIdIndex' property flag on table is set to Yes
*/

static void FullTextIndexesDemo()
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDatasource;
    QueryRun                queryRun;
    QueryBuildRange         queryRange;
    FullTextIndexesDemo     fullTextIndexes;

    queryBuildDatasource = query.addDataSource(tableNum(FullTextIndexesDemo));
    queryRange           = queryBuildDatasource.addRange(fieldNum(FullTextIndexesDemo,
					            AxVersion));
    queryRange.rangeType(QueryRangeType::FullText);
    /*
    [Technet] Space characters are treated as implicit Boolean OR operators.
    There is a space character in the string parameter in call
    queryBRange4.value("dynamics 0");.
    */
    queryRange.value('dynamics 0');

    queryRun = new QueryRun(query);

    while (queryRun.next())
    {
        fullTextIndexes = queryRun.get(tableNum(FullTextIndexesDemo));
        Debug::printTab(DebugPrintTab::ActiveX, fullTextIndexes.AxVersion);
    }
}

Happy Full indexing in 2012 ;)

Categories: X++ stuffs

How to write UtcDateTime value along with Timezone in AX2012

September 25, 2011 Leave a comment

In AX2O12, we can manage record relationship that are valid for a specific date range, by setting the ValidTimeStateFieldType property to UtcdateTime.

Let’s draw a scenario where you need to parse an XML which was built on lower version (S.O) and push data into AX2012 system using AIF. In scenario as above, we might end-up having relation w.r.t LogisticsPostalAddress which has ValidFrom as an attribute and the framework XMLWriter would validate the data only if the parsed UtcDateTime is correct as shown format.



The sample code shown below will explain how the dateTime is parsed an converted into UtcDateTime format which could be accepted by the AIF when they are surrogate Key relationship on ‘ValidFrom’ on the master table.



The below image displays the virtual table which was created at run-time to show the ValidFrom entry made against the user timezone.



Based on the created record the dateTime is converted into UtcDateTime and displayed to the users.

Example illustrated above is attached in the following link, named as SharedProject_Conversion_DateTimeToTimeZone.

https://skydrive.live.com/?sc=documents&cid=264a0056cbcbb1d3#cid=264A0056CBCBB1D3&id=264A0056CBCBB1D3%21630&sc=documents

Welcome AX2012 :)

Categories: X++ stuffs

Multiple XPO Import Version – 3

June 20, 2011 1 comment



Hey Guys,

I have added a small Add-in feature to the existing tool which will create a Project for all the imported elements. Each import will have a following namespace (ImportProject) followed by underscore and a random number appended to the namespace. The Time stamp is also added in html log to know at what time the elements were imported.



The Project name can be modified based on your requirement. To achieve the following please mofidy the code in the below part

public void createProject(TreeNodePath         _path,
                          identifiername       _projectName
= strfmt("%1%2_%3", "@SYS105127", "@SYS36368", new Random().nextInt()),
ProjectSharedPrivate _type
= ProjectSharedPrivate::ProjShared)

Please let me know your suggestion if any so that i can/modify more to this XPO import tool :)

Download Link: http://cid-264a0056cbcbb1d3.office.live.com/embedicon.aspx/.Public/SharedProject_MultipleXPOImport_WorkingStill_v3.xpo

Categories: X++ stuffs

We are AX Bloggers :)

June 5, 2011 1 comment


Nice video :) Thanks Mahesh for sharing this AX search for users who can refer our blogs

Categories: X++ stuffs

AX2012 Hands on Labs

May 19, 2011 Leave a comment


Friends,
There are hands on lab session on AX2012 available on Partner Source. For more information please refer the following link here

Topics covered in the hands-on lab are as follows:

1.  Workflow Implementation
2.  Accounts Payable
3.  Accounts Receivable Enhancements
4.  Expense Management
5.  Migrating Reports to SSRS
6.  Employee Procurement
7.  Client Forms
8.  Export Extend and Refresh
9.  Edit Budgets in Excel
10. Sales Quotations in Word
11. Import Data Using Excel
12. Project Accounting 

Thanks Fee :) for sharing us the information.

Categories: X++ stuffs

X++ Script to renamePrimaryKey across companies

May 18, 2011 Leave a comment


Hey Guys :)

During data upgrade to AX2012 we had issue in ‘Product Upgrade’ preprocessing checklist. Validation errors were observed due to presence of same item in different companies with different ‘DimGroupId’ or ‘ItemType’ values.

Only way left to resolve the issue was by renaming the ‘ItemId’ of these items. So we renamed all the items which are of type ‘StopItem’ to ‘%Old Item Name’.

Accordingly the String size of ‘itemIdBase’ and ‘EcoResProductNumber’ EDTs were increased to 30 to avoid the truncation of ‘ItemId’ and ‘ProductNumber’.

The best option left to optimize the work load instead of manually updating the item was to use the renamePrimaryKey method.

static void renamePKInventTable()
{
    #File
    #define.prefixItem('Old')
    InventTable     inventTable;
    container       getCompanyList;
    int             i;
    DataAreaName    id;

    container getCompany()
    {
        dataArea  dataArea;

        // Virtual Companies should not be added.
        while select dataArea
            where dataArea.isVirtual != NoYes::Yes
        {
            getCompanyList += [dataArea.id];
        }

        return getCompanyList;
    }
    ;

    getCompanyList = getCompany();

    for(i = 1; i<= conlen(getCompanyList); i++)
    {
        id = conpeek(getCompanyList, i);

        changeCompany(id)
        {
            inventTable.clear();

            while select inventTable
              where inventTable.RMCItemType == RMCItemType::StopItem
                 && inventTable.dataAreaId  == id
                 && !(inventTable.ItemId like 'Old*')
            {
                ttsbegin;

                inventTable.ItemId = #prefixItem +
                                     #delimiterSpace +
                                     inventTable.ItemId;

                inventTable.renamePrimaryKey();

                if(inventTable)
                {
                    inventTable.selectForUpdate(boolean::true);
                    inventTable.ItemName  = inventTable.ItemId;
                    inventTable.NameAlias = inventTable.ItemName;
                    inventTable.update();
                }

                ttscommit;
            }
        }
    }
}

This X++ script renamed all the Items in Item Master across companies except the virtual company;)

Categories: X++ stuffs

Multiple XPO Import Version – 2

January 25, 2011 Leave a comment


Hi folks ;) ,

There was a major issue in the version 1 of the Multiple XPO Import tool. Each time when a multiple XPO’s are imported, a confirmation dialog keeps popping up for all the existing elements. This behavior seems to be very annoying to the users.

Now the code design pattern is slightly modified. When an import is performed all the objects are imported SILENTLY without confirmation dialog show up to users even for existing elements.

Note: Please use at your own risk when trying on Production environment

If you still wanted to get confirmation dialog for existing element please use the Version – 1 link:
   http://axblog4u.wordpress.com/2010/10/29/multiple-xpo-import-tool-for-dynamics-ax/

I have a made minor changes w.r.t existing version.

   1) No Email support.
       Instead, once the objects are imported the log file is opened automatically.



   2) The log report shows the Imported User & User Preferred Time zone.

In the vNext – 3, I shall be adding new feature like:

    1) Adding the imported object to the Project at run-time so that user can track the imported objects based on the time.

Download Link @ Version: 2
http://cid-264a0056cbcbb1d3.office.live.com/self.aspx/.Public/SharedProject%5E_MultipleXPOImport%5E_v2.xpo

Categories: X++ stuffs

Form Size Exceeds the Maximum Pixel in Dynamics AX

January 22, 2011 2 comments

One of my colleague had a strange warning as stated below in the screenshot.


In order to find the root cause of the issue I designed a form named FormPixelExceeds with Datasource as “Invent Table”.

In the Design – Grid property instead of having Width, Height set to ‘Auto’, we changed the values of fixed width and height value.

When the compiler level was set to 4 it started throwing BP warning stating:
The form size exceeds the maximum of 1280 * 924 pixels. Current size 1296 * 940 (1.25\% * 1.73\%).



In order to fix it we had to reduce the form pixel width & height (i.e. Width: 1000, Height: 650) instead of setting to mentioned value in the screenshot. So any developers reading this article should make sure the form should not exceed the predefined pixel else it would result in BP warning.

There is no hard and fast rule that developer need to assign values to Width, Height instead set those properties to accomodate Column Width/Column Height such that the form does’nt take too much of space on the screen. Hope this piece of information was useful…

Lets welcome AX2012 :) in the year 2011 :P

Categories: X++ stuffs
Follow

Get every new post delivered to your Inbox.