- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @sumityadav8
It appears you're trying to combine both client-side and server-side logic within a single UI Action, which is a common point of confusion in ServiceNow
- current.u_state == 21; → this is a comparison, not an assignment.
- It never changes the value. You need = not ==.
May you try this code separate
OnClick client function (validation only):
function checkres() {
var res = g_form.getValue('u_resolution_notes');
if (!res || res.trim() == '') {
g_form.setMandatory('u_resolution_notes', true);
g_form.showFieldMsg('u_resolution_notes', "Resolution notes is mandatory", 'error');
return false; // stop here
}
// If valid, submit to server script
gsftSubmit(null, g_form.getFormElement(), 'hr_in_resolved');
}
Server-side script (update record):
if (typeof g_form == 'undefined') { // server-side only
if (action.getName() == 'hr_in_resolved') {
current.u_state = 21; // <-- assignment, not comparison
current.update();
action.setRedirectURL(current);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @sumityadav8
your script is mixing up client-side and server-side logic, thats the reason for not working
On the client script you should only handle form validation (making resolution notes mandatory, showing field message, etc.). That part with g_form.setMandatory and gsftSubmit is correct.
Updating the record (current.u_state = 21; current.update();) should be done in the UI Action’s server-side script section, not in the client-side onClick.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @sumityadav8
It appears you're trying to combine both client-side and server-side logic within a single UI Action, which is a common point of confusion in ServiceNow
- current.u_state == 21; → this is a comparison, not an assignment.
- It never changes the value. You need = not ==.
May you try this code separate
OnClick client function (validation only):
function checkres() {
var res = g_form.getValue('u_resolution_notes');
if (!res || res.trim() == '') {
g_form.setMandatory('u_resolution_notes', true);
g_form.showFieldMsg('u_resolution_notes', "Resolution notes is mandatory", 'error');
return false; // stop here
}
// If valid, submit to server script
gsftSubmit(null, g_form.getFormElement(), 'hr_in_resolved');
}
Server-side script (update record):
if (typeof g_form == 'undefined') { // server-side only
if (action.getName() == 'hr_in_resolved') {
current.u_state = 21; // <-- assignment, not comparison
current.update();
action.setRedirectURL(current);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday
Hi @sumityadav8
your script is mixing up client-side and server-side logic, thats the reason for not working
On the client script you should only handle form validation (making resolution notes mandatory, showing field message, etc.). That part with g_form.setMandatory and gsftSubmit is correct.
Updating the record (current.u_state = 21; current.update();) should be done in the UI Action’s server-side script section, not in the client-side onClick.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India