Field-level rules define how a field will behave under certain circumstances. The field-level rules for a given field are stored within the family rule project for the family to which the field belongs.
Each family rule project contains a code item for each field that exists within the family. The rules for a given field are stored in the file that corresponds to that field.
The following types of rules can be defined for each family field.
Rule Type | Description | Associated Function |
---|---|---|
Required | Determines whether or not a value must be entered into a field before a record can be saved in the family. | IsRequired |
Validation | Lets you define criteria that will be used to validate values that are entered into a field. | Validate |
Valid Values | Lets you define a list of values that will be available for selection in the field. You will be able to select any value from those defined in the list of Valid Values. | GetPickList |
Default Value | Defines the default value that will be provided for a field. When you create a new record, the default value will be provided automatically. You can accept the default value or specify a different value. | GetDefaultInitialValue |
Disabled | Determines when, if ever, the field will be disabled, or locked from modification. | IsDisabled |
Format | Determines the formatting that will be applied to values entered into a field. | FormatValue |
Formula | Calculates the value in the field using a formula that has been specified through rules. | GetCalculatedValue |
You can develop custom field-level rules manually by accessing the code item for the appropriate field and inserting the custom code. The code for each rule type must be defined within the appropriate function, which serves as a container for the code for that rule.
Instead of making a field always required, you may prefer to make it required only if another field in the same record also contains a value. For example, assume that the Recommendation family contains the logical field Completed (MI_REC_COMPL_FLG), which is meant to be flagged by a user after a recommendation has been completed. The Recommendation family also contains the Completed Date field, which is meant to contain the date the recommendation was completed. Therefore, you want to create a rule so that when the Completed field is set to True, the Completed Date field is required.
To enforce this condition, you would create a Required rule on the Completed Date field that looks like this:
Public Overrides Function IsRequired() As Boolean
If Object.Equals(CurrentEntity.Fields("MI_REC_COMPL_FLG").Value, True) Then
Return True
Else
Return False
End If
End Function
The portion of the code shown in red (MI_REC_COMPL_FLG) identifies the Field ID of the field that you want to use to enforce the Required rule condition, and the portion on the If line shown in blue (True) specifies the value that the field must contain.
Consider an example where the Recommendation family contains the field Create Work Request? (MI_REC_CREATE_SAP_NOTIF_FLG). Suppose you want to create a rule that validates the presence of an active external interface (e.g., Oracle) before GE Digital APM triggers the creation of a work request. Should the rule return no active external interface, then no work request will be created.
You could enforce the need for a work request management system by creating the following Validation rule for the Create Work Request? field:
Public Overrides Function Validate(ByRef newValue As Object) As Meridium.Core.DataManager.Customization.FieldValidationStatus
If InterfaceUtility.InterfacesActive(Me.ApplicationUser) Or _
InterfaceUtility.OracleInterfacesActive(Me.ApplicationUser) Or _
InterfaceUtility.MaximoInterfacesActive(Me.ApplicationUser) Then
Return FieldValidationStatus.Success
End If
Return FieldValidationStatus.Failure(InterfaceUtility.EAM_INTERFACES_NOT_ACTIVATED)
End Function
Consider another example for a validation rule, where in the Asset Criticality Analysis datasheet, the Analysis Definition Family section contains the field Analysis ID. Suppose you want to create a rule that validates if the Analysis ID exists in the system database.
If the field validation status is a failure, then we can have the rule take the message text as input and return a failure message. We can embed a hyperlink in the validation failure error message, causing the hyperlink to be shown along with the error message under the field.
If the field validation status is a successful, then we can have the rule take the message text as input and return a success message. The message would be displayed under the field.
Within a list of available values, a blank value can be useful for clearing a previously selected value. When you select the blank value, it will clear whatever value had previously been selected in the list.
For example, the following code excerpt show a static Valid Values rule that will construct a list containing the values A, B, and C.
Public Overrides Function GetPickList() As DynamicPickList
Dim pickList As DynamicPickList
'Use MyBase.CreatePickList(True) if you want a restricted PickList
'Use MyBase.CreatePickList(False) if you want an unrestricted PickList
pickList = MyBase.CreatePickList(True)
PopulatePickList(pickList)
Return pickList
End Function
Public Overrides Sub PopulatePickList(ByVal pickList As DynamicPickList)
pickList.AddRange("A|B|C".Split("|"c))
End Sub
You can add a null value to the list by inserting the code pickList.Add(DBNull.Value) above the line pickList.AddRange("A|B|C".Split("|"c)). The resulting code would look like this:
Public Overrides Function GetPickList() As DynamicPickList
Dim pickList As DynamicPickList
'Use MyBase.CreatePickList(True) if you want a restricted PickList
'Use MyBase.CreatePickList(False) if you want an unrestricted PickList
pickList = MyBase.CreatePickList(True)
PopulatePickList(pickList)
Return pickList
End Function
Public Overrides Sub PopulatePickList(ByVal pickList As DynamicPickList)
pickList.Add(DBNull.Value)
pickList.AddRange("A|B|C".Split("|"c))
End Sub
Consider an example where the Recommendation family contains the field Final Approver Name (MI_REC_FINAL_APPROVE_NAME_C). Suppose you want to create a Default Value rule on the Final Approver Name field to set it by default to the name of the user who is logged in to GE Digital APM at the time the record is approved. The resulting code would look like this:
Public Overrides Function GetDefaultInitialValue() As Object
Return RecommendationUtilities.RecommendationDefaultValues.FinalApproverName(Current Entity)
End Function
It may be appropriate to disable some fields conditionally, based on the value in another field.
Consider an example where the Equipment family contains the fields Plant Section (MI_EQUIP000_PLANT_SECTION_C) and Person Responsible for Plant Section (MI_EQUIP000_PLANT_SECT_DESC_C). The Person Responsible for Plant Section field does not need to be enabled until the Plant Section field contains a value.
To enforce this logic, you could create the following rule on the Person Responsible for Plant Section field so that it is disabled when the Plant Section field is empty. The resulting code would look like this:
Public Overrides Function IsDisabled() As Boolean
If Convert.IsDBNull(CurrentEntity.Fields("MI_EQUIP000_PLANT_SECTION_C").Value) Or Object.Equals(CurrentEntity.Fields("MI_EQUIP000_PLANT_SECTION_C").Value, "") Then
Return True
Else
Return False
End If
End Function
You may want to format character fields so that the value typed in the field appears in all capital letters. Consider an example where the Recommendation family contains the field Completion Comments (MI_REC_CLOSE_COMME_TX), and you want to view values in that field in all capital letters. You could create the following Format rule on the Completion Comments field to do so:
Public Overrides Function FormatValue(ByVal value As Object) As String
If Not Convert.IsDBNull(CurrentEntity.Fields("MI_REC_CLOSE_COMME_TX").Value) Then
Return UCase(CStr(value))
Else
Return ""
End If
End Function
For some fields, rather than requiring users to specify a value, you may want to populate the field with a value that is calculated from values entered in other fields. Consider an example where the Work History family contains three cost fields:
In this case, you may want to require users to enter values in the Maintenance Cost and Production Cost fields and then calculate the value for the Total Cost field by adding together the values in the Maintenance Cost and Production Cost fields. To implement this functionality, you could create the following Formula rule for the Total Cost field:
Public Overrides Function GetCalculatedValue() As Object
'Total Cost = Maintenance Cost + Production Cost
Dim maintCost As Double = 0
Dim prodCost As Double = 0
If Not Convert.IsDBNull(CurrentEntity.Fields("MI_EVWKHIST_MAINT_CST_N").Value) Then
maintCost = Convert.ToDouble(Current Entity.Fields("MI_EVWKHIST_MAINT_CST_N").Value)
End If
If Not Convert.IsDBNull(CurrentEntity.Fields("MI_EVWKHIST_PRDN_CST_N").Value) Then
prodCost = Convert.ToDouble(CurrentEntity.Fields("MI_EVWKHIST_PRDN_CST_N").Value)
End If
Return maintCost + prodCost
End Function
Copyright © 2018 General Electric Company. All rights reserved.