Onload client script button not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours 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
an hour 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
42m ago
it is still taking me to the new record page and not setting the checkbox field u_cirt_in_progress to false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
33m ago
When i use type="button" I can't able to click the button. I tried removing the g_form.save(); but still it is taking me to the new record page
