Generation of CodePage using X++


Case Study: In this demo scenario, we are going to build Windows Code page using X++ class.
For this project, I have build a generation class which basically returns the list of available codePage.

private void buildCodePage()
{
    System.Text.EncodingInfo[]    encodingInfoArray;
    System.Text.EncodingInfo      encodingObject;

    RecordInsertList              recordInsertList =  
                                  new RecordInsertList(tableNum(CodePageTable));
    System.Exception              ex;
    InteropPermission             permission = 
                                  new InteropPermission(InteropKind::ClrInterop);
    ;

    // Clear always the codePage data is available
    delete_from codePage;

    try
    {
        permission.assert();
        encodingInfoArray = System.Text.Encoding::GetEncodings();

        // BP Deviation Documented.
        for (i = 0; i <= 
                    CLRInterop::getAnyTypeForObject(
                    encodingInfoArray.get_Length()) - 1; 
            i++ )
        {
            encodingObject = encodingInfoArray.GetValue(i);

            codePage.CodePage    = System.Convert::ToString(
                                   encodingObject.get_CodePage());
            codePage.DisplayName = System.Convert::ToString(
                                   encodingObject.get_DisplayName());

            recordInsertList.add(codePage);
        }

        ttsbegin;
                recordInsertList.insertDatabase();
        ttsCommit;

        CodeAccessPermission::revertAssert();
    }
    catch (Exception::CLRError)
    {
        ex = ClrInterop::getLastException();

        if (ex != null)
        {
            ex = ex.get_InnerException();
            if (ex != null)
            {
                error(ex.ToString());
            }
        }
    }
}


Once this code is executed the runtime formRun displays the required output as shown below.

This form displays the codePage

AX2012 DLink: SharedProject_CodePage happy AX2012 🙂

AX20009 DLink: SharedProject_CodePage happy AX2009 🙂

Advertisements
Categories: X++ stuffs

Dynamics AX2012: Create Custom Service using X++

January 24, 2012 5 comments


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

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 2 comments

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



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 :)


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

Categories: X++ stuffs
%d bloggers like this: