
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 01:01 PM
Hello guys,
That's possible to use g_form.showFieldMsg for multiple fields at the same time without having to repeat the script?
For example, I need to display an error message in the following fields: Category, Configuration Item, Assignment Group and Short description.
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 01:10 PM
Hi,
You'd have to use the script in a loop such as:
var fields = ["field1","field2","field3"];
for (var i = 0; i < fields.length; i++) {
g_form.showFieldMsg(fields[i], "message", 'error');
}
Example:
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 01:10 PM
Hi,
You'd have to use the script in a loop such as:
var fields = ["field1","field2","field3"];
for (var i = 0; i < fields.length; i++) {
g_form.showFieldMsg(fields[i], "message", 'error');
}
Example:
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 01:13 PM
Thanks a lot, Allen! That's worked well!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 01:15 PM
Hi, either repeat the script or make an array of field names then loop through it setting the field msg to true, along the lines of
var arr = ["category", "cmdb_ci", "assignment_group", "short_description"];
var arr1 = ["msg for category", "msg for ci", "msg for assig group", "msg for short desc"];
for (var i = 0; i < arr.length; i++) {
g_form.showFieldMsg(arr[i], arr1[i]);
}
Stupid script but its just an idea, as currently there isnt any mass showFieldMsg APIs from ServiceNow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 01:58 PM
Great idea too! Thanks for your help!