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-04-2025 01:17 AM
@Medi C Thank you for the reply
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-04-2025 01:15 AM
Greetings,
@Medi C , @Chaitanya ILCR , @Sandeep Rajput , @Vishal Jaswal - Thank you for the replies.
This is an automated process where the RITM records need to get created based on few no of days related conditions/filters used on a different table (ex. expiry date of a request). i tried writing a scheduled job and a flow chart for this. And both are working fine in creation of data and addition of values.
But what would be the best approach for creating of records (flow or Scheduled job that runs at night).
Note: we have checked an approx no of records for 8 days. it has max of 250 and min of 20. The number will increase when the application goes live.
Please suggest me the best approach.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:49 AM
Better to go with flow (low-code, no-code) approach and easy to maintain.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:41 AM
Hello Sakshi, Please try below code
function onSubmit() {
// Get the value of the 'requested_for' field
var reqFor = g_form.getValue('requested_for');
// Create a GlideAjax object to call the server-side script
var fetchValue = new GlideAjax('Automation_Client_UTILS');
fetchValue.addParam('sysparm_name', 'fetchGroup'); // Specify the function to call
fetchValue.addParam('sysparm_sysID', reqFor); // Pass the sysID of the requested_for user
// Use an asynchronous call with getXMLAnswer
fetchValue.getXMLAnswer(function(answer) {
// Set the value of the 'description' field with the response from the server
g_form.setValue('description', answer);
// Programmatically submit the form after receiving the response
g_form.submit();
});
// Prevent the default form submission during the initial call
return false;
}
please mark helpful if it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 01:47 AM
why not use before insert/update business rule and set the value?
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