Defining the Script of an Autofix

If the custom check you have defined supports an automatic correction, you can type the body of this function in the Autofix Script tab of the custom check properties.

The autofix is visible in the Check Model Parameters dialog box, it is selected by default if you select the Execute the Automatic Correction by Default check box in the General tab of the custom check properties.

By default, the Autofix Script tab displays the following script items:

  • %Fix% is the function name, it is passed on parameter obj. It is displayed as a variable, which is a concatenation of the name of the resource file, the name of the current metaclass, the name of the stereotype or criterion, and the name of the fix. If any of these names contains an empty space, it is replaced by an underscore

  • The variable outmsg is a parameter of the fix function. You need to specify the fix message that will appear when the fix script will be executed

  • The return value line that indicates if the fix succeeds or not

We will use the same example as in section Defining the script of a custom check, to define an autofix script that removes the columns with incorrect data type from index.

  1. Click the Autofix Script tab in the custom check properties.

    By default, the function is declared at the beginning of the script. You should not modify this line.

  2. Type a comment after the function declaration in order to document the custom check, and then declare the different variables used in the script:
    Dim c 'temporary  index column
    Dim col 'temporary column
    Dim position
    Dim DT_col
  3. Enter the function body:
    %Fix% = False
     If obj.type = "LF" or obj.type = "HG" or obj.type = "CMP" or obj.type ="HNG" Then
      For Each c In obj.IndexColumns
       Set col = c.column
       position = InStr(col.datatype,"(") 
       If position <> 0 Then
        DT_col = Left(col.datatype, position -1) 
       Else 
        DT_col = col.datatype
       End If
       If (Ucase(DT_col) = "VARCHAR") And (col.length > 255) Then
        outmsg = "Automatic correction has removed column " & col.Name & " from index."
        c.Delete
        %Fix% = True
       End If
      Next
     End If


  4. Click Apply to save your changes.