Logo
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
EPL Standings
 
 
Windows Server

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

- 2015 Chevrolet Camaro Z28 - The Legend Returns
- Wagon Audi Allroad Vs. Subaru Outback
- 996 Carrera 4S is Driving Perfection
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.
Top Search -----------------
- Windows Server 2008 R2 : Work with RAID Volumes - Understand RAID Levels & Implement RAID
- Windows Server 2008 R2 Administration : Managing Printers with the Print Management Console
- Configuring Email Settings in Windows Small Business Server 2011
- Windows Server 2008 R2 : Configuring Folder Security, Access, and Replication - Implement Permissions
- Monitoring Exchange Server 2010 : Monitoring Mail Flow
- Windows Server 2008 R2 :Task Scheduler
- Windows Server 2008 R2 : File Server Resource Manager
- Windows Server 2008 R2 : Installing DFS
- Exchange Server 2010 : Managing Anti-Spam and Antivirus Countermeasures
- Windows Server 2008 R2 : Configuring Folder Security, Access, and Replication - Share Folders
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
 
 
Most view of day
- Microsoft Dynamic CRM 4 : Data Migration (part 4) - Creating a Data Migration
- Leveraging Social Networking Tools in SharePoint 2010 : Restricting User Access to and Creation of My Site Sites
- Microsoft Dynamics AX 2009 : The MorphX Tools - Code Compiler & Dynamics AX SDK
- Windows Server 2003 : Securing Network Communications Using IPSec - Troubleshooting Data Transmission Security
- Building BizTalk Server 2009 Applications : Setting up new BizTalk projects
- Iphone Application : Using Gesture Recognizers (part 4)
- Microsoft Dynamics AX 2009 : Working with Data in Forms - Processing multiple records
- Windows Server 2008 R2 : Elements of Group Policy (part 5)
- Maintaining and Troubleshooting Windows 7 : Using Windows RE (part 1) - Accessing the WinRE
- Windows Server 2008 R2 : Deploying and Using Windows Virtualization - Quick Migration and Live Migration (part 2)
Top 10
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 8) - Configuring Transport Rules
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 7) - Configuring Journal Rules
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 6) - Verifying Edge Subscriptions, Removing Edge Subscriptions
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 5) - Getting Edge Subscription Details, Synchronizing Edge Subscriptions
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 4) - Creating an Edge Subscription
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 3) - Enabling Anti-Spam Features
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 2) - Configuring the Transport Dumpster , Configuring Shadow Redundancy
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 1) - Configuring Transport Limits
- Advanced Windows 7 Programming : Working in the Background - DEVELOPING TRIGGER-START SERVICES (part 7)
- Advanced Windows 7 Programming : Working in the Background - DEVELOPING TRIGGER-START SERVICES (part 6)
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro