Ratnakar7
Mega Sage

When working with ServiceNow, developers often encounter scenarios where they need to customize platform behavior but are restricted from directly modifying Out-of-Box (OOB) Script Includes due to upgrade risks. One elegant solution to this challenge is using a wrapper class.

 

-> What Is a Wrapper Class?

A wrapper class in ServiceNow is a custom Script Include that extends an existing OOB Script Include. It allows you to override or enhance specific methods without altering the original file. This approach ensures your changes are upgrade-safe, meaning they won't be lost or conflict when ServiceNow updates the platform.

Wrapper classes follow this pattern:

var CustomWrapper = Class.create();
CustomWrapper.prototype = Object.extendsObject(OOBScriptInclude, {
    // Override or extend methods here
});


-> Why Not Modify OOB Script Includes Directly?

Many OOB Script Includes carry warnings like:
"Warning: This is a Medium Risk file that might get updated again in later releases. Do not alter this file unless necessary."

Ratnakar7_3-1766769257409.png

Modifying these files directly can:

  • Break functionality after upgrades

  • Cause merge conflicts

  • Void support agreements

Instead, use wrapper classes to safely override logic.


-> Example: Employee Center Widget

In the My Active Items widget of Employee Center, users often see item counts like "9+" for Requests, Tasks , etc. However, some customers want to display the actual count (e.g., 12, 25, 88) instead of the capped "9+".

Ratnakar7_1-1766768484126.png

 

 

The logic for this resides in the OOB Script Include ActivityConfigurationUtilSNC, specifically in the method getActivityData(). Since this file is flagged as risky to modify, we use a wrapper class to override the method safely.

-> Solution: Wrapper Class Implementation

Here's how I implemented the solution:

var ActivityConfigurationUtil = Class.create();
ActivityConfigurationUtil.prototype = Object.extendsObject(ActivityConfigurationUtilSNC, {
    getActivityData: function(recordLimit) {
        // Original logic copied from ActivityConfigurationUtilSNC
        ...
        itemData.totalItemCount = itemData.itemCount;

        // Commenting out the logic that caps the count at '9+'
        /*if (itemData.itemCount > 9) {
            itemData.itemCount = '9+';
        }*/
       itemData.itemCount = itemData.totalItemCount;
        ...
    },
    type: 'ActivityConfigurationUtil'
});

 

This wrapper class overrides the getActivityData method and removes the condition that replaces actual counts with "9+". The widget now displays the true item count, meeting the customer's requirement without touching the original Script Include.

Using wrapper classes is a best practice for customizing ServiceNow in a future-proof way. Whether you're tweaking logic, enhancing features, or bypassing limitations, wrappers give you the flexibility to innovate without compromising upgrade safety.

Have you used wrapper classes in your implementations? Share your experience or questions below!

 

Thanks,
Ratnakar

 

3 Comments
k4zuy
Tera Contributor

Hi @Ratnakar7 ,

not modifying ootb records and creating a wrapper instead is curse and blessing in my opinion because no skipped records will be created, so no information about ootb changes reaches me. This could prevent new features from being applied which could obsolete my customizations. Is there a way to still get informed about code changes in the ootb record?
Thank you in advance and kind regards!

Ratnakar7
Mega Sage

Hi @k4zuy ,

You're absolutely right - using a wrapper avoids skipped records, but it also means we don't automatically see OOTB changes during upgrades. We can still track them under Upgrade Monitor/Upgrade Details and the Compare Against Baseline feature, which let us review what changed in OOTB artifacts even if we didn't customize them. Combined with release notes, these tools give us visibility into new features so we can decide whether our wrapper logic needs to be updated.

Thanks,
Ratnakar

k4zuy
Tera Contributor

Hi @Ratnakar7 ,
thanks for your quick answer! Could you give me some more information on that "Compare Against Baseline" feature? I didn't know about that. 
Thank you in advance and kind Regards!