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:
-
FCTaskRepository
extendsFCRepository
to handle records from thetask
table and its child tables. Since ServiceNow uses table inheritance, any repository that needs to work with a table inheriting fromtask
(likeincident
orsn_hr_core_case
) should extendFCTaskRepository
. This ensures proper handling of task-specific fields and behaviors. -
IncidentRepository
extendsFCTaskRepository
to work specifically with incident records -
HRCaseRepository
extendsFCTaskRepository
to work specifically with HR case records -
Other specialized repositories like
UserRepository
andDepartmentRepository
extend directly fromFCRepository
since 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