That's possible to use g_form.showFieldMsg for multiple fields at the same time?

Flavio Tiezzi
Kilo Sage

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!

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

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:

find_real_file.png

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

4 REPLIES 4

Allen Andreas
Administrator
Administrator

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:

find_real_file.png

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thanks a lot, Allen! That's worked well!

harun_isakovic
Mega Guru

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.

Great idea too! Thanks for your help!