We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to add "Reset" button for clear values of variable in service Catalog form.

Not applicable

I want to add button on service catalog form ---> "Reset", which will clear all variables values.

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage

Hello @Ganesh Palve ,

you can create a custom type variable and tag your widget in that variable which will render the button on the catalog form 

find_real_file.png

find_real_file.png

 

please try below code in the widget 

Html:

<button type="button" class="btn btn-danger btn-block" ng-click="c.clearValue()">Reset Values</button>

Client controller:

api.controller=function($scope) {
	/* widget controller */
	var c = this;

	c.clearValue = function() {
		alert('test');
		var g_form = $scope.page.g_form;
		
	

			var allFields = g_form.getFieldNames();
		alert(allFields);

			for(var fieldName in allFields){
			

				g_form.setValue(allFields[fieldName],'');

			

		}
	};
};

Please try this and if it works please mark my answer as correct

 

 

 

 

View solution in original post

14 REPLIES 14

Not applicable

find_real_file.png

hello @Ganesh Palve 

please pass $Scope in your function in the first line

api.controller =function($scope){

 

And also use this to clear value it clears all the values

var allFields = g_form.getFieldNames();
		alert(allFields);

			for(var fieldName in allFields){
			

				g_form.setValue(allFields[fieldName],'');

 

@Ganesh Palve  did it work?

if yes please mark my answer correct 

Not applicable

Heyy Mohit..

Thank You very very much brother...

code working as expected

 

 

--

Thank You

Your Friend - Ganesh Palve

@Ganesh Palve  No problem man! 

Any time 

mark my answer correct and close the thread so that it will be helpful for others with same query