Saturday, December 20, 2014

Tutorial: Auto-Complete functionality on form controls

I guess all of you are familiar with the Auto-Complete feature present in Dynamics AX. Whenever you type in a repeated value in a control on AX forms, an automatic suggestion pops up next to the entered characters and the user can choose to accept the suggestion (for example, by tabbing out of the control).
There are methods on the form (specifically, the FormRun class) that provide you with a more tight control over the auto-completion list available to the user, and this blog post will describe the behavior of these methods, as there are a few not obvious things there.

Method signature Method behavior description
getAutoCompleteString(int _elementIndex) Retrieve the auto-complete string saved under the specified index in the auto-completion list of the form.
The indexing is not control-specific, and is not very efficient at keeping the number of values in the list low, so you will see values from multiple controls here.

The method returns a container containing 2 values:
- the auto-completion string value
- the index of this string in the auto-completion list
getAutoCompleteString(int _startIndex, FormControl _control, str _searchStr) Retrieve the auto-complete string for the specified control, finding the first one in the list starting from the specified startIndex + 1.

If _searchStr is also specified, it will find the first matching entry in the list with index > startIndex. This is the closest behavior to what happens when a user types in a certain character in the entry control on the form and the kernel needs to search and populate the auto-complete value for it.

Note: There’s a small bug in this function, where it does not return the full string value for longer texts. A workaround is to use the above “overload” and retrieve the full value by index.
setAutoCompleteString(string _string, anytype _control) The first argument is clear, and that is the auto-completion string to add to the list of suggestions.

The second argument is presented as _control, but can accept either an instance of a FormControl, or an integer value of the list item index to set.

If the _string already exists in the auto-completion list for this control, nothing will happen. If it does not exist, a new item will be added to the list (number of items cannot exceed 300) with the next available index.
setAutoCompleteString(string _string, anytype _index) The auto-completion list item at index _index will be updated in the list with the specified _string value.

This method “overload” basically allows you to override a particular value in the list with a new value.
delAutoCompleteString() Deletes all auto-completion items from the list, regardless of which control they are bound to, if any.
delAutoCompleteString(anytype _index) Deletes the item with the specified index from the auto-completion list.
delAutoCompleteString(anytype _control) Deletes all auto-completion items for the specified control from the list.

When a value in one of the controls on the form is modified, this value is also automatically added to the auto-completion list. With the above methods, however, you can control, if this value should actually stay there, or be immediately removed.
This way you can, for example, restrict the user to only be provided with auto-completion hints from a certain list (similar to IntelliSense).

I created a simple form to demonstrate all the above methods in action.

Tutorial auto-complete capabilities form
Tutorial form to demo auto-completion capabilities

You can download the form from my OneDrive.

Apart from the above methods, there is also a global setting which allows you to control auto-completion list availability for a particular user. This is control on the User options screen, as highlighted in the below image:

Autocomplete in User options
User options form

If this check box is not set, auto-completion suggestions will not be shown to the user when entering data on forms, even though the auto-completion list is still maintained behind the scenes.

Wednesday, December 03, 2014

Tip: Connecting the Warehouse management device portal to a different company or partition in Dynamics AX

As a follow up to my blog post about fixing an annoying error with the warehouse mobile device portal (see original post here), I got a number of people asking the following question:
"How do I install/configure the mobile portal to work in more than one company/partition?"
This is possible, and relatively easy, even though it might not be the most intuitive thing to do. Here's a quick walk-through of allowing work users to access another company account portal.

The Warehouse mobile device portal (WMDP) as of today only supports connecting to a single company account in a single partition. This is driven by the Active directory account used as the identity for the IIS application pool that is used to run the WMDP.

Which means that in order to access another company, we need to:

  • Create another Active directory account
  • Install another instance of the WMDP
    • Use a different port number than the ones already installed
    • Use the above AD user as the identity for the app pool
  • Add a user in AX for the above Active directory account
    • Do it in the partition you want to connect to
    • Set the default company to the one you want to connect to
    • Don't forget to assign the correct security role
    • Hint: You can also set the default user language, which will impact the WMDP site as well
  • Create all the necessary Warehouse management data in the new partition/company. That includes the Display settings, Warehouse workers and mobile device users, warehouses, etc.

Note, that you should avoid having the same AD user (used for WMDP) be part of multiple partitions. Only the first partition (alphabetically) will be connected to, but it becomes confusing for people looking at the data.

Once these steps are complete, you should be able to use the new link (with the new port) to connect to the mobile device portal and log in as a work user from the new company account.