Home > X++ stuffs > Generating Lookups using SysAttributes Class – Dynamics AX2012

Generating Lookups using SysAttributes Class – Dynamics AX2012


Case Study: In earlier or current release we have different ways of displaying lookups using table lookup, field group lookups, building reference lookup from custom form using FormAutoLookupFactory.

Building custom lookups for displaying AOT elements using SysModelElements/UtilElementsId was usually performed by Query/QueryBuildDataSource instead we can generate same using SysAttribute . Similiar type of functionality is implemented across AX2012 and one such instance is usage of attribute for displaying Workflow queues.

Generating lookups using Attributes

Design Approach: We are building runtime lookup by checking attributes whose values are ‘True’ and adding to the temporary table. This way we would display all the classes which has the following attribute syntax:

[SysClassEnabledAttributes(boolean::true, classStr(SysEnabledDocument))]

Where SysClassEnabledAttributes is a attribute base class which extends SysAttribute which helps us to build the required lookup.

Code Pattern:

/// <summary>
///    Finds the classes that extend the 
///    <c>SysEnabledAttributes</c> class that are queue enabled.
/// </summary>
/// <returns>
///    A <c>SysAttributeTmp</c> table buffer.
/// </returns>
public static SysAttributeTmp  getAllAttributes()
{
    #define.sysAttribute("SysClassEnabledAttributes")
    SysAttributeTmp                    attributes;
    List                               list;
    SysDictClass                       dictClass;
    DictClass                          currentClass;
    ListEnumerator                     listEnumerator;
    boolean                            flag = true;
    SysClassEnabledAttributes          attribute;

    dictClass = new SysDictClass(classNum(AbstractAttributesClass));
    listEnumerator = new ListEnumerator();
    list           = dictClass.extendedBy();
    listEnumerator = list.getEnumerator();

    while (listEnumerator.moveNext())
    {
        currentClass = new DictClass(listEnumerator.current());

        attribute = currentClass.getAttribute(#sysAttribute);
        if (attribute != null)
        {
            flag = attribute.parmFlag();

            if (flag)
            {
                attributes.Name        = dictClass.name();
                attributes.Description = attribute.parmName();
                attributes.insert();
            }
        }
    }

    return attributes;
}

Please check out for the design implementation in the shared location. Happy Attributing AX2012 ;)
SharedProject_Lookup_Attributes

About these ads
Categories: X++ stuffs Tags:
  1. September 4, 2012 at 11:38 am

    i oo can’t download the attachment. my id is zahircogniz@hotmail.com

    • September 6, 2012 at 11:18 am

      Sent to your email. Please check it now.
      \Thanks

  2. June 24, 2012 at 12:50 am

    can’t download the attachment on windows-live.

    • June 25, 2012 at 12:00 pm

      Can you send me your personal mail id? I can share it across to you from my hotmail id.

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 32 other followers

%d bloggers like this: