- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:32 AM
We have a requirement where they want to automatically close info message(g_form.addInfoMessage) after 30 sec. In order to do that i have to find and write time out to each info message in system.
I am looking for is there anyway we can define it globally at some place so where ever the info message is written it will take 30 sec to time out only?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:55 AM
Yes, you can create a client script that automatically detects and closes all info messages after 30 seconds without modifying each individual message. Here's the most effective approach:
function onLoad() {
// Override addInfoMessage to mark auto-close messages
var originalAddInfoMessage = g_form.addInfoMessage;
g_form.addInfoMessage = function(message, persist) {
var msgElement = originalAddInfoMessage.call(this, message, persist);
if (!persist) {
msgElement.dataset.autoclose = 'true';
}
return msgElement;
};
// Check for messages every second
setInterval(function() {
var messages = document.querySelectorAll('[data-autoclose="true"]');
messages.forEach(function(msg) {
if (!msg.dataset.closeTime) {
msg.dataset.closeTime = Date.now() + 30000;
} else if (Date.now() > parseInt(msg.dataset.closeTime)) {
$(msg).fadeOut(500, function() {
$(this).remove();
});
}
});
}, 1000);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:56 AM
I don't think you can define it globally, but you will have to use script and give timeout
// Display the info message
g_form.addInfoMessage('This is my info message');
// Clear the info message after 30 seconds
setTimeout(function() {
g_form.clearMessages();
}, 30000); // 30000 milliseconds = 30 seconds
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
04-04-2025 09:17 AM
Thank you for marking my response as helpful.
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
04-06-2025 07:58 PM
Hope you are doing good.
Did my reply answer your question?
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
04-04-2025 02:55 AM
Yes, you can create a client script that automatically detects and closes all info messages after 30 seconds without modifying each individual message. Here's the most effective approach:
function onLoad() {
// Override addInfoMessage to mark auto-close messages
var originalAddInfoMessage = g_form.addInfoMessage;
g_form.addInfoMessage = function(message, persist) {
var msgElement = originalAddInfoMessage.call(this, message, persist);
if (!persist) {
msgElement.dataset.autoclose = 'true';
}
return msgElement;
};
// Check for messages every second
setInterval(function() {
var messages = document.querySelectorAll('[data-autoclose="true"]');
messages.forEach(function(msg) {
if (!msg.dataset.closeTime) {
msg.dataset.closeTime = Date.now() + 30000;
} else if (Date.now() > parseInt(msg.dataset.closeTime)) {
$(msg).fadeOut(500, function() {
$(this).remove();
});
}
});
}, 1000);
}