Overview
graph TD;
A[FCRepository]-->B[FCTaskRepository];
B-->C[IncidentRepository];
B-->D[HRCaseRepository];
A-->E[UserRepository];
A-->F[DepartmentRepository];
The diagram above illustrates the repository pattern implementation in ServiceNow. At the root is the FCRepository base class which provides core database interaction functionality. From there, specialized repositories inherit and extend this base functionality:
-
FCTaskRepositoryextendsFCRepositoryto handle records from thetasktable and its child tables. Since ServiceNow uses table inheritance, any repository that needs to work with a table inheriting fromtask(likeincidentorsn_hr_core_case) should extendFCTaskRepository. This ensures proper handling of task-specific fields and behaviors. -
IncidentRepositoryextendsFCTaskRepositoryto work specifically with incident records -
HRCaseRepositoryextendsFCTaskRepositoryto work specifically with HR case records -
Other specialized repositories like
UserRepositoryandDepartmentRepositoryextend directly fromFCRepositorysince they work with independent tables that don't inherit fromtask
Note
Extended repositories can override methods from their parent repository by implementing methods with the same name. For example, IncidentRepository could override getActiveByAssignedToMe() from FCTaskRepository to add incident-specific filtering or behavior.
This pattern provides several benefits: - Code reuse through inheritance - Consistent data access patterns - Separation of concerns between data access and business logic - Type safety through specialized repositories - Easier testing and maintenance