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