Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

numeric variable display type change required.

Vivek Kumar Tya
Tera Contributor

Hi,

 

The requirement i have received is to have a numeric variable added to a Catalog item.

 

Default Appearance:- The only numeric variable - Numeric Scale variable type option seems to be appearing the below format in service portal:-

 

VivekKumarTya_0-1696770838804.png

 

Appearance required:- However, the requirement is to have it in the below form in Service Portal:-

 

VivekKumarTya_1-1696770918440.png ,  

 

Please advise how this can be achieved for a Numeric variable in a Catalog item in ServiceNow ?

3 REPLIES 3

Danish Bhairag2
Tera Sage

Hi @Vivek Kumar Tya ,

 

You need to create a custom variable where u can add widget to it & create field of that type by writing custom code in that widget.

 

Thanks,

Danish

Hi @Vivek Kumar Tya ,

 

Create a new Variable of type Custom as shown below:

 

DanishBhairag2_0-1696878723119.png

 

 

For widget field click on search icon then create New Record provide some name for that record & paste the below code

 

Html Code:

 

<!-- HTML markup for the numeric field with up and down arrows -->

<input type="text" ng-model="quantity" />

<button ng-click="increaseQuantity()">▲</button>

<button ng-click="decreaseQuantity()">▼</button>

 

Client Controller Code:

 

// AngularJS controller logic for the widget

function($scope, $http) {

    $scope.quantity = 1; // Default quantity

    // Function to increase quantity

    $scope.increaseQuantity = function() {

        $scope.quantity++;

    };

    // Function to decrease quantity (prevent negative values)

    $scope.decreaseQuantity = function() {

        if ($scope.quantity > 1) {

            $scope.quantity--;

        }

    };

    // Add additional logic to handle form submission, backend interactions, etc.

}

 

Save the record. Open the form on the portal & check if the display is as per expectation.

 

DanishBhairag2_1-1696878723086.png

 

 

 

 

Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

RichardL2
Tera Contributor

Trying to use your script / approach.  It appears the function is missing.

The up down arrows do not work.

RichardL2_0-1718856655527.png