Populate the the field info message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 02:04 AM
Hi All,
I have one requirement in incident form, when the source is "ABC" then need to select the approve field only 2 entries at the same time need to populate the field info message also. here i had done some coding , in client script -->on change, code is working fine i can't add more that two members, but the field message will not display because of the i m setting this line--->g_form.setValue('u_approvers', oldValue);
Now i need to populate the field messge and also only add the two entries , any one suggestion me how to add this?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var source = g_form.getValue('u_source');
if (source === 'abc') {
var approvers = g_form.getValue('u_approvers').split(',');
if (approvers.length > 2) {
g_form.showFieldMsg("u_approvers", ('You can only select up to 2 approvers.'));
g_form.setValue('u_approvers', oldValue);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 02:08 AM - edited 08-07-2024 02:20 AM
@DeepikaR1661877 Remove the brackets "g_form.showFieldMsg('u_approvers', 'You can only select up to 2 approvers.');"& try below code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var source = g_form.getValue('u_source');
if (source == 'abc') {
var approvers = g_form.getValue('u_approvers').split(',');
if (approvers.length > 2) {
g_form.showFieldMsg('u_approvers', 'You can only select up to 2 approvers.');
g_form.setValue('u_approvers', oldValue);
}
}
}
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 02:13 AM
Hi @DeepikaR1661877 Try below code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var source = g_form.getValue('u_source');
if (source === 'abc') {
var approvers = g_form.getValue('u_approvers').split(',');
if (approvers.length > 2) {
g_form.showFieldMsg('u_approvers', 'You can only select up to 2 approvers.', 'info');
g_form.setValue('u_approvers', oldValue);
} else {
g_form.hideFieldMsg('u_approvers');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 02:17 AM
only minor mistake in your code; just correct that and it will work
g_form.showFieldMsg("u_approvers", 'You can only select up to 2 approvers.'); // the message should not be wrapped within round brackets
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 02:23 AM
Hi @DeepikaR1661877 ,
Remove the brackets and change the order keep the field message after setValue as below,
if (isLoading || newValue === '') {
return;
}
var source = g_form.getValue('u_source');
if (source === 'abc') {
var approvers = g_form.getValue('u_approvers').split(',');
if (approvers.length > 2) {
g_form.setValue('u_approvers', oldValue);
g_form.showFieldMsg("u_approvers", 'You can only select up to 2 approvers.');
}
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang