How to Create a Form with Repeating Fields Based on Yes/No Selection in ServiceNow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2025 12:13 PM
Hi everyone,
I need help creating a form in ServiceNow with the following requirements:
- Variable 1: Single-line text input
- Variable 2: Single-line text input
- Variable 3: Single-line text input
- Variable 4: Yes/No selection
The goal is that if Variable 4 is set to "Yes," the form should repeat Variable 1, Variable 2, and Variable 3 and 4 to allow the user to enter additional data. This repetition should continue until Variable 4 is set to "No."
How can I achieve this in ServiceNow, either through form design or scripting?
Thanks in advance for any guidance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2025 12:45 PM
Hello @Ashok_Bandla
You need to create a MRVS and condition on "Add Row" button there, whose visibility you will make false if the value selected for the variables 4 is yes.
Let me know if you need specific script. This cannot be done without DOM Manipulation. And I don't think there is any other way of repetitive variables set.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 07:48 AM
Hi Shivalika,
Thanks for the details! A specific script would be really helpful for implementing the MRVS and condition on the "Add Row" button. Could you please share it?
Regards,
Ashok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2025 12:12 PM
Hello @Ashok_Bandla
Please try below 👇 script -
// Define the name of the Yes/No variable (Make this configurable)
var yesNoVariable = 'variable_4'; // Replace with actual variable name
// Get the value of the Yes/No selection
var yesNoValue = gForm.getValue(yesNoVariable);
// Check if Multi-Row Variable Set exists
var mrvsName = 'multi_row_variable_set'; // Replace with actual MRVS name
var mrvsElement = gForm.getControl(mrvsName);
if (mrvsElement) {
// Hide "Add" button if "No" is selected
if (yesNoValue === 'No') {
mrvsElement.parentElement.querySelector('.variable_set_row_add').style.display = 'none';
} else {
mrvsElement.parentElement.querySelector('.variable_set_row_add').style.display = 'block';
}
}
Let me know in case of any issues. Change the names as per your requirement.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2025 12:57 PM
I wrote this i debgged but, it is not working. Can you look at this script