set value on list field using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 11:24 PM
Greetings,
We have created an onSubmit Client Script to fetch groups based on name, and save it to a list field.
the values are not getting saved.
we tried to set values on a string field and we see that the values getting entered and then cleared out after few seconds.
Client Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 11:37 PM - edited 04-03-2025 11:38 PM
Hello @sakshi18
You can relate this scenario as a race between Submit (submission of form/record) vs asynchronous GlideAjax and you have already figured that Submission of the form/record is winner because before your getResponse callback is executed, the form submission is already done.
Solution: you need to ensure that the form submission waits for the GlideAjax call to complete. You can achieve this by returning false from the onSubmit function to prevent the form from submitting immediately.
So in your client script make two changes:
add return false;
below this line: fetchValue.getXML(getResponse);
and add g_form.submit();
below this line: g_form.setValue('description', answer);
Hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:16 AM
Thank you for the reply @Vishal Jaswal ,
i tried this
but the form is loading on a loop and won't stop.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 11:43 PM
@sakshi18 This issue is occurring because by the time your GlideAjax call return the response the form is already submitted and the value in the filed is not saved.
Please refer to this article https://www.servicenow.com/community/developer-articles/async-validation-in-onsubmit-catalog-client-... where the steps to handle this is mentioned.
If you wish to handle this in Service portal then you can refer to https://snowexpertrohit.com/itsm-code/glideajax-in-portal/
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:19 AM
@Sandeep Rajput Thanks for the reply,
we are doing this on form and catalog is not involved