Several versions of the same element typically exist. These versions might emanate from various layers or revisions in version control, or they could be modified versions that exist in memory. AX 2012 has a built-in Compare tool that highlights any differences between two versions of an element.
The comparison shows changes to elements, which can be modified in three ways:
- A metadata property can be changed.
- X++ code can be changed.
- The order of subnodes can be changed, such as the order of tabs on a form.
Starting the Compare tool
To open the Compare tool, right-click an element, and then click Compare. A dialog box opens where you can select the versions of the element you want to compare, as shown in Figure 2-26.
FIGURE 2-26 The Comparison dialog box.
The versions to choose from come from many sources. The following is a list of all possible types of versions:
- Standard layered version types These include SYS, SYP, GLS, GLP, FPK, FPP, SLN, SLP, ISV, ISP, VAR, VAP, CUS, CUP, USR, and USP.
- Old layered version types (old SYS, old SYP, and so on) If a baseline model store is present, elements from the files are available here. This allows you to compare an older version of an element with its latest version. For more information about layers and the baseline model store, see Chapter 21, “Application models.”
- Version control revisions (Version 1, Version 2, and so on) You can retrieve any revision of an element from the version control system individually and use it for comparison. The version control system is explained later in this chapter.
- Best practice washed version (Washed) A few simple best practice issues can be resolved automatically by a best practice “wash.” Selecting the washed version shows you how your implementation differs from best practices. To get the full benefit of this, select the Case Sensitive check box on the Advanced tab.
- Export/import file (XPO) Before you import elements, you can compare them with existing elements (which will be overwritten during import). You can use the Compare tool during the import process (Command > Import) by selecting the Show Details check box in the Import dialog box and right-clicking any elements that appear in bold. Objects in bold already exist in the application.
Upgraded version (Upgraded) MorphX can automatically create a proposal for how a class should be upgraded. The requirement for upgrading a class arises during a version upgrade. The Create Upgrade Project step in the Upgrade Checklist automatically detects customized classes that conflict with new versions of the classes. A class is conflicting if you’ve changed the original version of the class, and the publisher of the class has also changed the original version. MorphX constructs the proposal by merging your changes with the publisher’s changes to the class. MorphX requires access to all three versions of the class—the original version in the baseline model store, a version with your changes in the current layer in the baseline model store, and a version with the publisher’s changes in the same layer as the original. The installation program ensures that the right versions are available in the right places during an upgrade. Conflict resolution is shown in Figure 2-27.
FIGURE 2-27 How the upgraded version proposal is created.
Figure 2-28 shows the Advanced tab, on which you can specify comparison options.
FIGURE 2-28 Comparison options on the Advanced tab.
The following list describes the comparison options shown in Figure 2-28:
- Show Differences Only All equal nodes are suppressed from the view, making it easier to find the changed nodes. This option is selected by default.
- Suppress Whitespace White space, such as spaces and tabs, is suppressed into a single space during the comparison. The Compare tool can ignore the amount of white space, just as the compiler does. This option is selected by default.
- Case Sensitive Because X++ is not case sensitive, the Compare tool is also not case sensitive by default. In certain scenarios, case sensitivity is required and must be enabled, such as when you’re using the best practice wash feature mentioned earlier in this section. This option is cleared by default.
- Show Line Numbers The Compare tool can add line numbers to all X++ code that is displayed. This option is cleared by default but can be useful during an upgrade of large chunks of code.
Using the Compare tool
After you choose elements and set parameters, start the comparison by clicking Compare. Results are displayed in a three-pane dialog box, as shown in Figure 2-29. The top pane contains the elements and options that you selected, the left pane displays a tree structure resembling the AOT, and the right pane shows details that correspond to the item selected in the tree.
FIGURE 2-29 Comparison results.
Color-coded icons in the tree structure indicate how each node has changed. A red or blue check mark indicates that the node exists only in a particular version. Red corresponds to the SYS layer, and blue corresponds to the old SYS layer. A gray check mark indicates that the nodes are identical but one or more subnodes are different. A not-equal-to sign (≠) on a red and blue background indicates that the nodes are different in the two versions.
Details about the differences are shown in the right pane. Color coding is also used in this pane to highlight differences the same way that it is in the tree structure. If an element is editable, small action icons appear. These icons allow you to make changes to code, metadata, and nodes, which can save you time when performing an upgrade. A right or left arrow removes or adds the difference, and a bent arrow moves the difference to another position. These arrows always come in pairs, so you can see where the difference is moved to and from. If a version control system is in use, an element is editable if it is from the current layer and is checked out.
Although AX 2012 provides comparison functionality for development purposes only, you can reuse the comparison functionality for other tasks. You can use the available APIs to compare and present differences in the tree structure or text representation of any type of entity.
The Tutorial_CompareContextProvider class shows how simple it is to compare business data by using these APIs and present it by using the Compare tool. The tutorial consists of two parts:
- Tutorial_Comparable This class implements the SysComparable interface. Basically, it creates a text representation of a customer.
- Tutorial_CompareContextProvider This class implements the SysCompareContextProvider interface. It provides the context for comparison. For example, it creates a Tutorial_Comparable object for each customer, sets the default comparison options, and handles context menus.
Figure 2-30 shows a comparison of two customers, the result of running the tutorial.
FIGURE 2-30 The result of comparing two customers by using the Compare API.
You can also use the line-by-line comparison functionality directly in X++. The static run method on the SysCompareText class, shown in the following code, takes two strings as parameters and returns a container that highlights differences in the two strings. You can also use a set of optional parameters to control the comparison.
public static container run(str _t1, str _t2, boolean _caseSensitive = false, boolean _suppressWhiteSpace = true, boolean _lineNumbers = false, boolean _singleLine = false, boolean _alternateLines = false)