How to create Reset button in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 05:04 AM
Hi Team,
I want to add a button in my catalog item as Clear Values and on clicking the button, it should clear the field values.
Please help.
Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 05:13 AM
Hi Vaishnavi,
Follow link that has solution that fits your business case.
Its a simple widget which will be used in variable of type Macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 05:21 AM
Hi Vaishnavi,
you can use this code in the UI action; It should be client side UI action
Onclick: clearFields();
Script:
function clearFields(){
var allFields = g_form.getFieldNames();
for(var fieldName in allFields){
g_form.clearValue(fieldName);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 05:22 AM
Hello Vaishnavi,
you can try something like this in your script. This way, you don't need to hardcode any fieldname.
var allFields = g_form.getFieldNames();
for(i=0;i<allFields.length;i++){
g_form.clearValue(allFields[i]);
}
Mark the comment as a correct answer and also helpful if this helps to solve the problelm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 05:43 AM
To also have it working in the Service Portal use this as UI Action:
Client: true
onclick: clearValues();
Script:
function clearValues() {
var allFields = g_form.getFieldNames();
for (i = 0; i < allFields.length; i++) {
g_form.setValue(allFields[i], '');
}
}