Whereas field-level rules control the behavior of specific fields within a record, family-level rules reside within the code item that represents an entity family and control actions performed against the entire record.
Family-level rules provide flexibility in determining how records will behave. Some of the most common uses of family-level rules include:
You can create family-level rules by developing custom code.
GE Digital APM supports the following family-level rule types.
Rule Type | Stores logic that is executed... |
---|---|
BeforeInsert | Before a record is created. |
AfterInsert | After a record is created. |
BeforeUpdate | After changes have been made to a record, before those changes are saved to the database. |
AfterUpdate | After changes to a record have been saved. |
BeforeDelete | Before a record is deleted. |
AfterDelete |
After a record has been deleted. |
A change to a record in the GE Digital APM database will trigger the appropriate rule regardless of the current user’s permissions. However, if a user does not have permissions for an action a rule is taking, the rule will not execute and the transaction will be rolled back and no changes will be made. Similarly, the transaction will be rolled back if an error occurs during the rule’s execution.
One use of an AfterInsert rule is to create a link between two families after a new record is created. Consider an example where, when you create a Functional Location record, you want to link it to the Site Reference record that represents the site that contains the functional location. You can accomplish this by creating a family-level rule for the Functional Location family.
The following code shows an example of an AfterInsert rule that you could write to create a link between the Functional Location record and the Site Reference record after the Functional Location record is created. You would insert this rule into the family-level code item for the Functional Location family.
Public Overrides Sub AfterInsert()
ManageSiteReference()
End Sub
Private Sub Manage Site Reference ()
Dim session As EntitySession = CurrentEntity.Session
If session Is Nothing Then
session = New EntitySession(ApplicationUser)
End If
Dim currentSite As SiteReference = SiteReference.LoadExisting(session, CurrentEntity)
Dim newSite As SiteReference = SiteReference.RetrieveSiteReference(session, CurrentEntity)
If currentSite Is Nothing AndAlso newSite Is Nothing Then
Return
End If
If currentSite Is Nothing And Not newSite Is Nothing Then
newSite.AddAssetToSite(CurrentEntity)
ElseIf Not currentSite Is Nothing And newSite Is Nothing Then
If Not CurrentEntity.Fields("MI_FNCLOC00_SAP_SYSTEM_C").Value Is DBNull.Value Then
currentSite.RemoveAssetFromSite(CurrentEntity)
End If
ElseIf currentSite.Key <> newSite.Key Then
currentSite.RemoveAssetFromSite(CurrentEntity)
newSite.AddAssetToSite(CurrentEntity)
End If
End Sub
Copyright © 2018 General Electric Company. All rights reserved.