Export (0) Print
Expand All

Code Rules

Microsoft Dynamics Nav 2009

The following tables show how code rules are used to remove unsupported triggers and methods. Code rules are written using syntax similar to regular expressions. A code rule uses one or more special words to match code on the form.

The following special words are used as tags to find and replace expressions, to create variables, and to move code and properties:

The following special words are used as placeholders for variables:

The following examples illustrate how code rules work and can be written. The first examples show simple find and replace rules. The next examples build on the find and replace rule.

<find> and <replace>

Use the <find> and <replace> special words to find specific code and replace it. If you omit the <replace> instruction in the code transformation rule, then the found code is deleted but not replaced with any code.

Code transformation rule Code before transformation Code after transformation
<find>
x := y;
MESSAGE('Hello');
x := y;
MESSAGE('World');
MESSAGE('Hello');
MESSAGE('World');
<find>
x := y;
<replace>
y := z;
MESSAGE('Hello');
x := y;
MESSAGE('World');
MESSAGE('Hello');
y := z;
MESSAGE('World');
<find>
x := TRUE;
<replace>
;
<find>
y := x;
<replace>
x := TRUE;
<find>
y := x;
<replace>
x := FALSE;
MESSAGE('Hello');
y := x;
MESSAGE('World');
NoteNote
Rules are evaluated from top to bottom. Rules are run again if a match is found.
MESSAGE('Hello');
;
MESSAGE('World');

<atTrigger>

Use the <atTrigger> special word to specify that you want to find and replace code only if it is in the specified trigger.

Code transformation rule Code before transformation Code after transformation
<find>
x := y;
<atTrigger>
OnOpenForm
OnInit=BEGIN
  MESSAGE('Hello');
  x := y;
  MESSAGE('World');
END;

OnOpenForm=BEGIN
  MESSAGE('Hello');
  x := y;
  MESSAGE('World');
END;
OnInitPage=BEGIN
  MESSAGE('Hello');
  x := y;
  MESSAGE('World');
END;

OnOpenPage=BEGIN
  MESSAGE('Hello');
  MESSAGE('World');
END;

<comment>

Use the <comment> special word to add comments to the CodeRules.txt file. The comment is ignored in the code transformation.

Code transformation rule Code before transformation Code after transformation
<find>
x := z;
<comment>
Hello world
x := z;
MESSAGE('Hello World');

MESSAGE('Hello World');

!var! and !var<int>!

Use the !var! special word to specify a variable in the code. A !var! in a code rule matches any variable. You can specify different variables by appending an integer to !var!, such as !var1! or !var2!.

Code transformation rule Code before transformation Code after transformation
<find>
y := !var!
<replace>
y := TRUE;
MESSAGE('Hello');
y := x;
x := z;
MESSAGE('World');
MESSAGE('Hello');
y := TRUE;
x := z;
MESSAGE('World');
<find>
!var1! := !var2!
<replace>
!var2! := !var1!
MESSAGE('Hello');
y := x;
x := z;
MESSAGE('World;);
MESSAGE('Hello');
x := y;
z := x;
MESSAGE('World');

<declareVariable>, <declareVariableType>, and !declaredVariable!

Use the <declareVariable> special word to specify that the transformed code must declare a new variable. The expression after the <declareVariable> special word is the name of the new variable. Use the <declareVariableType> special word to specify the data type of the new variable that is declared. Use the !declaredVariable! special word to specify that you want to use the new variable that you declared.

Code transformation rule Code before transformation Code after transformation
<find>
!currForm!.!var1!.HEIGHT(!var2!)
<replace>
!currForm!.!var1!.HEIGHT := !var2!

<find>
CurrForm.!var1!.HEIGHT;
<declareVariable>
!var1!Height
<declareVariableType>
Integer
<replace>
!declaredVariable!;
OnRun=BEGIN
…
  MESSAGE('Hello');
  CurrForm.x.HEIGHT(NewHeight);
  MESSAGE('World');
END;
VAR
  xHeight : Integer;
OnRun=BEGIN
…
  MESSAGE('Hello');
  xHeight := NewHeight;
  MESSAGE('World');
END;

!currForm!

Use the !currForm! special word to specify either the CurrForm or CurrReport system-defined variable.

Code transformation rule Code before transformation Code after transformation
<find>
!currForm!.EDITABLE := TRUE
<replace>
;
MESSAGE('Hello')
CurrForm.EDITABLE := TRUE;
MESSAGE('World');
MESSAAGE('Hello');
;
MESSAGE('World');
<find>
!currForm!.EDITABLE := TRUE
<replace>
;
MESSAGE('Hello')
CurrReport.EDITABLE := TRUE;
MESSAGE('World');
MESSAAGE('Hello');
;
MESSAGE('World');

<moveToProperty>, <moveValueToProperty>, and <movePropertyToControlName>

Use the <moveToProperty> and the <moveValueToProperty> special words to move a value to the specified property. Use the <movePropertyToControlName> special word to move this property to the specified control.

Code transformation rule Code before transformation Code after transformation
<find>
Text := '';
<declareVariable>
!control!HideValue
<declareVariableType>
Boolean INDATASET
<replace>
!declaredVariable! := TRUE;
<atTrigger>
OnFormat
<moveToProperty>
HideValue
<moveValueToProperty>
!declaredVariable!
<movePropertyToControlName>
!control!
SourceExpr := x;
OnFormat=BEGIN
  MESSAGE('Hello');
  Text := '';
  MESSAGE('World');
END;
NoteNote
Assume that the preceding code is on a control. In this example, SourceExpr = x. The rule functions in the same way if the code is in a control with the Name property = x, or ID = x.
VAR
  xHideValue : Boolean INDATASET;
SourceExpr = x;
HideValue = xHideValue;
OnFormat=BEGIN
  MESSAGE('Hello');
  xHideValue := TRUE;
  MESSAGE('World');
END;

<moveCodeToTrigger> and <moveToTrigger>

Use the <moveCodeToTrigger> special word to specify the code that you want to move to a trigger. Use the <moveToTrigger> special word to specify the trigger to which you want to move the code.

Code transformation rule Code before transformation Code after transformation
<find>
y := x;
<atTrigger>
OnDeactivateForm
<replace>
;
<moveToTrigger>
OnCloseForm
<moveCodeToTrigger>
y := x;
OnDeactivateForm=BEGIN
  MESSAGE('Hello');
  y := x;
  MESSAGE('World');
END;
OnInit=BEGIN
  MESSAGE('Hello');
  y := x;
  MESSAGE('World');
END;
OnClosePage=BEGIN
  y := x;
END;
OnInit=BEGIN
  MESSAGE('Hello');
  y := x;
  MESSAGE('World');
END;

Community Additions

ADD
Show:
© 2014 Microsoft