OBLYTECH Logo
OBLYTECH Logo

Add custom business rules to an SLA

To add custom business rules to an SLA, first decide which custom fields belong on the task SLA record and which belong on its parent task. Keep engine-managed timing fields out of your write logic. Then choose an update method that avoids recursive processing, and test performance and audit consequences before deployment.

Plan the fields before adding custom SLA logic

Start with the information the business needs, rather than a script that changes a timer. A requirement to display a calculated breach time beside a task is different from a requirement to change how the SLA measures time. Write down which outcome you need before deciding where the rule should run.

You can add custom fields to the task SLA table and populate them with business rules. Adding a custom field is a schema change. Confirm on your release that it leaves the SLA engine untouched. Task SLA records are updated whenever the task changes, so any rule that runs on them should be cheap. Treat additional processing as work that may run repeatedly, even when a field seems minor.

Prepare a field plan with the destination, source value, reason for storing it, and intended consumer. For a copied breach time, distinguish the engine’s calculated value from the custom field that displays a copy. Give that distinction to the people building reports so they do not mistake a stored copy for an Name the owner of each destination field too, since the engine owns the default timing fields and your team owns the custom ones.

For example, a design might keep an internal classification on the task SLA while copying a breach time to a custom field on the parent task. These destinations need separate review: populating additional SLA data and updating the parent have different processing risks. A single phrase such as “add an SLA field” leaves too much undecided.

If the underlying agreement is still unclear, settle the difference between an SLA, OLA, and underpinning contract before deciding which records the customization should affect.

A business rule that writes to default task SLA fields can conflict with the SLA engine. The Task SLA timing fields, including Breach time, which is the same as Planned end time, are powered by the SLA engine. Do not write to them as a way to change timing. Store any copy in a separate custom field with its own refresh rule. A value that looks correct immediately after an update is not evidence of a sound design.

Divide the request into two questions: does the business want different timing behavior, or does it want additional information about existing timing? For the first question, review the SLA configuration before proposing code. For the second, define a custom destination and identify the engine value to read without taking ownership of its calculation.

Use SLA start, pause, and stop conditions to frame a timing requirement. If the request concerns when an agreement begins or stops, describing that condition precisely is a better starting point than manually changing a calculated field.

As a design check, ask what should happen after the next calculation. A copied value should follow an agreed refresh policy. An engine-managed value should remain under engine control. If the proposed outcome depends on a custom write surviving the engine’s next update, reconsider the approach before implementation.

Add custom business rules to an SLA without recursion

The role required for the custom business rule procedure is admin. Before implementing it, understand the business rule processing model and identify the records that the proposed script will update.

As a design judgement, a task SLA rule that writes to its parent task can start another round of business rule processing on that parent. Draw the proposed update path in plain language: a task SLA changes, the rule writes to the parent, and that task update participates in further processing. Avoid a business rule on the task SLA table that updates the parent task directly. If the requirement really needs that write, test it first.

There are two approaches to consider for a required parent task update: suppress processing on the task update with setWorkflow(false), or generate a scheduled update through sys_trigger. Neither approach gives a custom rule ownership of the SLA engine’s default fields. Choose according to the processing consequences the business can accept.

Use setWorkflow(false) with an explicit audit decision

For this approach, call setWorkflow(false) on the task’s GlideRecord object before updating that task. The sequence matters: obtain the parent record, assign the custom value, suppress processing on that object, and then update it. The breach-time example uses a change in planned_end_time as the reason to copy the value. Record the order of the write and the suppression step in your change notes so reviewers can see the sequence.

The effect extends beyond one competing business rule. setWorkflow(false) disables processing of all engines, and the task update does not appear in the task’s audit history. Decide whether those consequences are acceptable before selecting this method. Do not approve it solely because it interrupts a recursive path.

Review the proposed update with the people responsible for task history and downstream behavior. Ask them to identify what they expect to observe after the copy. If those expectations require the suppressed processing or an audited task change, the design needs further work.

Create a scheduled task update

The alternative uses the business rule’s Script field to generate a scheduled job that updates the task. For immediate queuing, the job must have type Run once and a next action time of Now. Queuing the work immediately should not be treated as proof that the destination has already been updated.

ScheduleOnce provides functions for identifying the target record, supplying the script, and creating the appropriate sys_trigger record. Plan the target and copied value together so the scheduled update has a clear purpose. Check this behavior on your instance and release before adopting the design.

For help planning this work, see ServiceNow implementation.

Test the copy and the processing it causes

Build a focused test around the chosen source field and destination. Record the starting values, cause a relevant SLA change, and inspect the result. Then introduce an unrelated update to check whether the custom logic does unnecessary work. These are acceptance checks to define for your implementation, Start the first check after the next SLA calculation, not at the moment of the update. The engine can ignore or overwrite a value written to a default field at that point, so a reading taken immediately after your write proves little. Record which calculation you compared against so the repeat test can use the same reference.

  1. Check that the intended custom field receives the intended source value on the correct record.
  2. Inspect a later SLA calculation to confirm that the customization does not rely on overriding engine-managed fields.
  3. For a suppressed task update, verify the expected absence from task audit history and assess the consequences of disabled engines.
  4. For scheduled processing, verify the target record, generated work, and eventual destination value separately.
  5. Exercise repeated relevant changes and inspect whether the resulting update pattern meets the business requirement.

Include a timing sequence in the acceptance record, not just a final screenshot. If the source changes twice before someone reads the destination, the requirement should say which value that reader expects. This is particularly important when evaluating scheduled work, where observing the source and observing the destination are separate checks.

Measure the added work under a representative pattern of task SLA updates. Review repeated reads, repeated writes, and job creation as separate costs. A rule can produce the right value in a single test while still doing more work than the requirement needs. Keep the change condition narrow enough to express the intended event.

Diagnose unexpected results before changing more logic

If a default timing value changes back after calculation, investigate field ownership first. Adding another rule to restore the custom value can deepen the conflict with the engine. Return to the distinction between an engine value and a custom destination, and Compare the value your rule wrote with the value left after the next calculation. That comparison shows whether the engine overwrote the write or the rule never ran, and the two causes need different fixes.

If parent task updates repeat, review the path from task SLA to task and back into processing. If a copied value is missing, inspect the change condition, target record, and chosen update method before altering the SLA definition.