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-1696870180102.png

 

 

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

 

VivekKumarTya_1-1696870180053.png

 

 ,  

 

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

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Vivek Kumar Tya Since the appearance you are looking to have is completely different than what numeric variable offers, you can choose to create a custom widget in angular and use the same with Variable type Custom with Label on your catalog item. 

Hi @Sandeep Rajput,

 

Thanks for the advise.

 

Please if you could share more details on the same ?

 

How to implement it practically ?

 

Required code and implementation steps ?

Please refer to this article to know more about variable type custom with label https://www.servicenow.com/community/developer-articles/usage-of-quot-custom-with-label-quot-variabl...

 

Regarding the widget, I do not have the code handy with me. You can search for similar angular widgets online and implement the same using their source code in ServiceNow.

@Vivek Kumar Tya ,

 

Create a new Variable as shown below

DanishBhairag2_1-1696878004123.png

For widget field click on search icon then 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 portal & check if the display is as per expectation.

DanishBhairag2_2-1696878445541.png

 

 

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

 

Thanks,

Danish