When we use g_form.setValue() on Client side function in UI Action, the value is not saving
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2025 11:04 AM
The values from client side script are not updating on the database
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 12:27 AM
Hello @AbhiramA7726340,
What are you trying to set based on your code? What’s the business requirement here?
Are you getting any errors while using g_form.setValue()?
Best Regards,
Anshul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 12:47 AM
@AbhiramA7726340 try using "g_form.save()" method in client script after setting up values.
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 12:50 AM
This function sets values on the form client-side and then submits the form with gsftSubmit.
But:
- The values do appear on the UI, but don’t save to the database.
- This often happens when you call a custom UI Action (like ‘check_in’) but don’t handle it properly server-side, or the server-side portion overrides it.
The line:
gsftSubmit(null, g_form.getFormElement(), 'check_in');
submits the form and triggers the UI Action with name=“check_in” on the server side.
But here’s the catch: if the server-side UI Action code doesn’t do anything with the form values (and especially if it’s set to “Client: true” and doesn’t let the form submit), your changes are not saved.
Solution:
Let the form submit normally
If your goal is just to set values and save the form, don’t use a custom UI Action name. Just submit the form:
g_form.setValue('check_in_time', new Date().toISOString());
g_form.setValue('status', 'completed');
g_form.submit();
This submits the form with all field values you just set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 01:10 AM
you are setting status in both client and server side.
why not set it in server side only?
OR
Simply use server side script
Update your script with 1st approach i.e. Client + Server
function StatusCompleted() {
gsftSubmit(null, g_form.getFormElement(), 'check_in');
}
if (typeof window == 'undefined') {
StatusBlocked();
}
function StatusBlocked() {
var gr = new GlideRecord('x_table_name');
gr.addQuery('sys_id', current.room);
gr.query();
if (gr.next()) {
gs.info(gr.getValue('status'));
gr.setValue('status', 'blocked');
gr.update();
}
current.setValue('check_in_time', new GlideDateTime());
current.setValue('status', 'completed');
action.setRedirectURL(current);
}
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