AX 2012: All About Lookups!

31
Dynamics AX Lookups Muhammad Anas Khan

description

 

Transcript of AX 2012: All About Lookups!

Page 1: AX 2012: All About Lookups!

Dynamics AX Lookups

Muhammad Anas Khan

Page 2: AX 2012: All About Lookups!

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

Page 3: AX 2012: All About Lookups!

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
Page 4: AX 2012: All About Lookups!

Muhammad Anas Khan4

Types of Lookup Forms

• Standard Lookup Forms

• EDT Lookup Forms

• Runtime Lookup Forms

• Enum Lookup (Not exactly a lookup form)

Page 5: AX 2012: All About Lookups!

Standard Lookup Forms

Example, Insight, Lab Activity, Demo

Page 6: AX 2012: All About Lookups!

Muhammad Anas Khan6

Example

Page 7: AX 2012: All About Lookups!

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

Page 8: AX 2012: All About Lookups!

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

Page 9: AX 2012: All About Lookups!

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

Page 10: AX 2012: All About Lookups!

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

Page 11: AX 2012: All About Lookups!

Muhammad Anas Khan

DEMOStandard Lookup Form

Page 12: AX 2012: All About Lookups!

EDT Lookup Forms

Example, Insight, Lab Activity, Demo

Page 13: AX 2012: All About Lookups!

Muhammad Anas Khan13

Example

Page 14: AX 2012: All About Lookups!

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

Page 15: AX 2012: All About Lookups!

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

Page 16: AX 2012: All About Lookups!

Muhammad Anas Khan

DEMOEDT Lookup Form

Page 17: AX 2012: All About Lookups!

Runtime Lookup Forms

Example, Insight, API, Demo

Page 18: AX 2012: All About Lookups!

Muhammad Anas Khan18

Example

Page 19: AX 2012: All About Lookups!

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

Page 20: AX 2012: All About Lookups!

Muhammad Anas Khan

lookup() method

Page 21: AX 2012: All About Lookups!

Muhammad Anas Khan

lookupReference() method

Page 22: AX 2012: All About Lookups!

Muhammad Anas Khan

DEMORuntime Lookup Form

Page 23: AX 2012: All About Lookups!

Enum Lookup

Example, Insight, API, Demo

Page 24: AX 2012: All About Lookups!

Muhammad Anas Khan24

Example

Page 25: AX 2012: All About Lookups!

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

Page 26: AX 2012: All About Lookups!

Muhammad Anas Khan

API

Page 27: AX 2012: All About Lookups!

Muhammad Anas Khan

DEMOEnum Lookup

Page 28: AX 2012: All About Lookups!

When to use what?

Page 29: AX 2012: All About Lookups!

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

Page 30: AX 2012: All About Lookups!

Muhammad Anas Khan

Page 31: AX 2012: All About Lookups!

Muhammad Anas Khan31

References

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

• Inside Microsoft Dynamics AX 2012 – Pg#188