Logo
CAR REVIEW
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
PREGNANCY
 
 
Windows Server

Microsoft Dynamics AX 2009 : Working with Data in Forms - Processing multiple records

6/12/2012 5:25:49 PM
In this recipe, we explore several ways of achieving this goal. We will modify the Items form in the Inventory management module by adding a new button to it, which lists currently selected records in the overview grid.

How to do it...

  1. 1. In AOT, open the InventTable form and create a new method with the following code:

    void processSelectedItems()
    
    {
    InventTable inventTableLocal;
    ;
    for (inventTableLocal = InventTable_ds.getFirst(true) ?
    InventTable_ds.getFirst(true) :
    InventTable;
    inventTableLocal;
    inventTableLocal = InventTable_ds.getNext())
    {
    info(strfmt(
    "You've selected item '%1'",
    inventTableLocal.ItemId));
    }
    }
    
  2. 2. Add a new Button to the form's ButtonGroup group:

    Property Value
    Name ProcessSelectedItems
    Text Process
    MultiSelect Yes

  1. 3. Override its clicked() with the following code:

    void clicked()
    
    {;
    super();
    element.processSelectedItems();
    }
    
  2. 4. To test the record selection, open Inventory management | Item Details, select several records using SHIFT or CTRL and click the Process button. The selected items should be displayed in the Infolog:

How it works...

The key element in this recipe is a for statement in processSelectedItems(). First, it checks if more than one record is selected by calling getFirst(true) on the InventTable form data source. If yes, the for loops all the selected records from the data source, otherwise it uses the cursor, which corresponds to the currently selected single record. All selected records are then stored in the local variable inventTableLocal. In this example, we just output inventory item numbers into the Infolog using the global info() function.

The ProcessSelectedItems button is used to call the function above once the user clicks it. Notice that its property MultiSelect is set to Yes to ensure it is still enabled when multiple records are selected.

There's more...

I have also experienced that sometimes Dynamics AX users struggle to select multiple records using SHIFT or CTRL. Sometimes, it is not clear that the form itself supports multiple record processing. In such cases a more convenient way of selecting multiple records could be to add a new checkbox in front of each record. This would remove all confusion and improve user experience. In order to implement that, we need to make few changes to the example above.

First, we add a new Map variable to the form's class declaration:

Map marked;

And in the form's init() right after the variable declaration section we create its instance:

marked = new Map(Types::Int64, Types::String);

Then, we create a new edit method on the InventTable data source with the following code:

edit boolean editMark(
boolean _set,
InventTable _inventTable,
boolean _mark)

{;
if (_set)
{
if (!_mark)
{
if (marked.exists(_inventTable.RecId))
{
marked.remove(_inventTable.RecId);
}
}
else
{
marked.insert(
_inventTable.RecId,
_inventTable.ItemId);
}
}
return marked.exists(_inventTable.RecId);
}


					  

We also add a new CheckBox to the top of the form's Grid in the Overview tab page with the following properties:

Property Value
Name Mark
Label Select
DataSource InventTable
DataMethod editMark

Finally, we have to modify processSelectedItems() to loop though the map. Replace the method with the following code:

void processSelectedItems()

{
MapEnumerator mapEnumerator;
;
mapEnumerator = marked.getEnumerator();
while (mapEnumerator.moveNext())
{
info(strfmt(
"You've selected item '%1'",
marked.lookup(mapEnumerator.currentKey())));
}
}

Open the Items form again and notice that now it has a new checkbox Select in front of each record. Pick several records using it and click Process. The selected items should be displayed in the Infolog:

The principle of this technique is that we use a Map type object to store the list of selected item numbers. The editMarked() method is bound to the checkbox control and is responsible for adding a record to the map upon user selection and removing it from the map if the user deselects the checkbox.

We also use the MapEnumerator class to retrieve item numbers from the map for further processing.
Other -----------------
- Microsoft Dynamics AX 2009 : Working with Data in Forms - Creating default data wizards
- Microsoft Systems Management Server 2003 : Developing Site Hierarchies (part 2) - International Site Considerations
- Microsoft Systems Management Server 2003 : Developing Site Hierarchies (part 1) - Network Performance
- BizTalk 2009 : Dealing with Extremely Large Messages (part 2) - Large Message Encoding Component
- BizTalk 2009 : Dealing with Extremely Large Messages (part 1) - Large Message Decoding Component
- Microsoft SQL Server 2008 R2 : Client Setup and Configuration for Database Mirroring
- Microsoft SQL Server 2008 R2 : Testing Failover from the Principal to the Mirror
- System Center Configuration Manager 2007 : Site and SQL Server Backups (part 3) - Restoring ConfigMgr Backups - Performing a Site Reset
- System Center Configuration Manager 2007 : Site and SQL Server Backups (part 2) - Restoring ConfigMgr Backups - ConfigMgr Functional Crash
- System Center Configuration Manager 2007 : Site and SQL Server Backups (part 1) - Backing Up ConfigMgr
- Security and Delegation in Configuration Manager 2007 : Securing Configuration Manager Operations
- Security and Delegation in Configuration Manager 2007 : Securing the Configuration Manager Infrastructure (part 4) - Securing Service Dependencies for Configuration Manager
- Security and Delegation in Configuration Manager 2007 : Securing the Configuration Manager Infrastructure (part 3) - Securing Configuration Manager Accounts
- Security and Delegation in Configuration Manager 2007 : Securing the Configuration Manager Infrastructure (part 2) - Securing Configuration Manager Communications
- Security and Delegation in Configuration Manager 2007 : Securing the Configuration Manager Infrastructure (part 1) - Securing Site Systems
- Backing Up the Exchange Server 2007 Environment : Establishing Service Level Agreements & Supporting Backups with Documentation
- Recovering from a Disaster in an Exchange Server 2007 Environment : Recovering Active Directory - The Active Directory Database
- Exchange Server 2010 : Managing Queues
- Exchange Server 2010 : Working with Queues - Accessing the Queue Viewer
- Windows Server 2008 Server Core : Managing the Hard Drive - Managing Partitions with the DiskPart Command
 
 
Most view of day
- Windows Phone 8 : Configuring Basic Device Settings - Screen Brightness (part 1) - Automatically Adjusting the Screen Brightness
- Windows Server 2003 on HP ProLiant Servers : Security Planning and Design (part 3) - Microsoft Software Update Service and Windows Update Service
- Windows Phone 8 : Developing for the Phone - Application Lifecycle (part 3) - Tombstoning
- Windows Server 2008 R2 high-availability and recovery features : Installing and Administering Windows Backup (part 1) - Installing Windows Server Backup
- Microsoft Exchange Server 2010 : Defining Email Addresses (part 3) - Email Address Policies - Creating a New Email Address Policy
- Securing Your SharePoint and Windows Azure Solutions : Configuring Shared Access Permissions for BLOB Storage - Using Certificate-Based Authentication
- Fine-Tuning MDT Deployments : Working with the MDT Database (part 4) - Extending the MDT Database with Custom Settings
- Microsoft Visio 2010 : Modifying a Graphic (part 1) - Resizing a Graphic
- SQL Server 2008 R2 : Performance Monitoring Tools (part 8) - Extended Events Catalog Views and DMVs
- Microsoft Dynamic AX 2009 : .NET Business Connector - Introduction
Top 10
- Sharepoint 2013 : SharePoint Designer 2013 (part 2) - Locking Down SharePoint Designer
- Sharepoint 2013 : SharePoint Designer 2013 (part 1) - New Features
- Sharepoint 2013 : Branding with the Design Manager (part 2) - Creating a Brand
- Sharepoint 2013 : Branding with the Design Manager (part 1)
- Sharepoint 2013 : SharePoint Designer and Branding - SharePoint 2013 User Interface
- Sharepoint 2013 : Microsoft Office Integration and Office Web Applications - Office Web Applications
- Windows Phone 8 : Scheduled Tasks - Scheduled Task API Limitations
- Windows Phone 8 : Scheduled Tasks - Updating Tiles Using a Scheduled Task Agent
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 5) - Editing an Existing To-Do Item
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 4) - Creating the To-Do Item Shell Tile, Saving a To-Do Item
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro