Onload client script button not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
49m ago - last edited 46m ago
Hi,
In the below onload client script, I kept the button "clear flag" when we click on this button it should make the checkbox field u_cirt_in_progress to false and should save the form and stay on the same page but right now it is taking me to the new record page after clicking and it is not setting the checkbox field u_cirt_in_progress to false. Could you please provide the fix for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
39m ago
Hello @krishnanara
You’re missing closing quote
g_form.setValue('u_cirt_in_progress', 'false');
Correct html button syntax
<button type="button" onclick="clearflag(); return false;">Clear Flag</button>
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
37m ago
not good practice to use g_form.save() in onLoad client script
there is issue in your syntax
try this
function onLoad() {
if (g_form.getValue('u_cirt_in_progress') == 'true') {
g_form.addErrorMessage(
'⚠ This account in progress ' +
'<button type="button" onclick="clearflag()">Clear Flag</button>'
);
}
}
function clearflag() {
// Set checkbox to false
g_form.setValue('u_cirt_in_progress', 'false');
// Save the record and stay on the same form
g_form.save();
// Prevent any default link/button behavior
return false;
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
