AX 2012: All About Lookups!

Post on 15-Jan-2015

5.042 views 3 download

Tags:

description

 

Transcript of AX 2012: All About Lookups!

Dynamics AX Lookups

Muhammad Anas Khan

Muhammad Anas Khan

Overview

• A lookup is a small form we use to select a value for a control

• A lookup can list the values in a grid or a form

• Often shows several fields that help us find and select the correct record

• For example, lookup for customer account number will also show customer name

• We can bind a lookup form to a field in the form datasource or a control in the form design

Muhammad Anas Khan3

Controls

• Following are the controls which can be bound to a lookup form:– DateEdit– GuidEdit– Int64Edit– IntEdit– RealEdit– ReferenceGroup– StringEdit– TimeEdit

Mohammad Danish Zaki (Tyler Technologies)
I think this slide is little bit confusing. Technically in lookups we can use every control.Because we can use forms as a lookup
Muhammad Anas Khan (Tyler Technologies)
Wording changed. These control are the one which can be bound to a lookup form

Muhammad Anas Khan4

Types of Lookup Forms

• Standard Lookup Forms

• EDT Lookup Forms

• Runtime Lookup Forms

• Enum Lookup (Not exactly a lookup form)

Standard Lookup Forms

Example, Insight, Lab Activity, Demo

Muhammad Anas Khan6

Example

Muhammad Anas Khan

Insight

• A standard lookup form is a system generated form

• To add a standard lookup form:– you bind a control to a field

– from the main table of the form data source

– that references the ID of a record in related table

• It uses a grid to list the records

• Field displayed in the control is dictated by the AutoIdentification field group of the related table

Muhammad Anas Khan

Insight

• Fields appearing in the lookup form are specified by a field group or another set of fields from the related table– Lookup bound to surrogate/natural foreign key

• shows fields in the AutoLookup field group by default

• shows fields used in TitleField1, TitleField2 properties of the table if AutoLookup is empty

• shows the first natural key of the table if AutoLookup, TitleField1, TitleField2 all are empty

• Use it whenever possible because:– Consistent experience across forms

– Easier to maintain as lookup forms get synced with field groups changes

Muhammad Anas Khan

Lab Activity

• In AOT, navigate to– Forms>>Form>>Data Sources>>Table>>Fields

• Open Fields node in a new window

• In the AOT that shows the form, navigate to– Designs>>Design

• Drag the field1 from the Fields list to the Design node of the form

• As a consequence, a control will be added to the Design node

• Check the properties of the newly added control

• Following above steps you will successfully build a standard lookup form

Muhammad Anas Khan

Lab Activity

ReferenceGroup control

• Name

• DataSource– Should be the intended table

from the form data source

• Label

• ReferenceField– Should be the intended

surrogate foreign key field from the DataSource table you want to bind the control to

Other controls

• Name

• DataField– Should be the intended foreign

key field in the DataSource table

• DataSource– Should be the intended table

from the form data source

• Label

• LookupButton– Should be set to Auto

After finishing lab activity, make sure the following fields have been set correctly

Muhammad Anas Khan

DEMOStandard Lookup Form

EDT Lookup Forms

Example, Insight, Lab Activity, Demo

Muhammad Anas Khan13

Example

Muhammad Anas Khan

Insight

• EDT can be used to bind a lookup form, from the AOT, to– A field in a form data source table– A control in a form design. The control can be unbound

• Style property, of the AOT form to be used as a lookup form, should be set to Lookup1

• Code must be added to the form that updates the value of the control when you select a record. For example, onClose method may be returning a record

• Use whenever the lookup form layout is complex

Muhammad Anas Khan

Lab Activity

• To add an EDT lookup form:– To a field, set the ExtendedDataType property of that field to the

name of the EDT

– To a control, set the ExtendedDataType property of that control to the name of the EDT

– Finally, set the FormHelp property of the EDT to the name of the AOT form you want to use as a lookup

Muhammad Anas Khan

DEMOEDT Lookup Form

Runtime Lookup Forms

Example, Insight, API, Demo

Muhammad Anas Khan18

Example

Muhammad Anas Khan

Insight

• It is a custom form you create with X++ code

• It can be added to a field in the form data source or a control in the form design

• To add a runtime lookup form to a field, override lookup or lookupReference method

• To add a runtime lookup form to a control, override lookup or lookupReference method

• Difficult to maintain because changes to the lookup require updates to the X++ code. Therefore use only when you need it

• Runtime lookup has higher precedence over standard and EDT lookups

Muhammad Anas Khan

lookup() method

Muhammad Anas Khan

lookupReference() method

Muhammad Anas Khan

DEMORuntime Lookup Form

Enum Lookup

Example, Insight, API, Demo

Muhammad Anas Khan24

Example

Muhammad Anas Khan

Insight

• Not exactly a lookup form

• Useful to know how to filter values in an enum lookup

• Possible in case of unbound controls

Muhammad Anas Khan

API

Muhammad Anas Khan

DEMOEnum Lookup

When to use what?

Muhammad Anas Khan

• Consistent experience across different forms• Easier to maintain as they get auto synced with

changes in field groups• Best to show fields from a field group of a related table

Standard Lookups

• Best to use if the lookup form layout is complex• Performance hit due to form rendering

EDT Lookups

• Best to leverage the power of query• Difficult to maintain because of the need to update the

code in case of changesRuntime Lookups

Muhammad Anas Khan

Muhammad Anas Khan31

References

• http://msdn.microsoft.com/en-us/library/aa597861.aspx

• Inside Microsoft Dynamics AX 2012 – Pg#188