Set value in reference field glide ajax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 09:25 PM - edited 04-22-2024 09:27 PM
Hi All,
I have created a glideajax to send data from client to script include, so the field is on the form: - ABC.
So I am sending sys_id in string form and sending this data to client side, the data is coming but how to set this list in reference field.
I am using g_form.setValue("field_name" , answer);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 09:32 PM - edited 04-22-2024 09:39 PM
Hi @Priya75 ,
You can use alert to check what values you are getting from server side like
alert(answer);
if you are getting values in JSON Format then you need to parse it and need to extract exact value from the answer and in case of XML . you can directly set value by using below script
g_form.setValue('field_name',answer);
Refer -
JSON -https://www.servicenow.com/community/developer-forum/populate-field-value-based-on-another-field-using-glide...
If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 09:42 PM
i am sending the list of records which are sys_id of records and i am sending it as a string comma separated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 09:52 PM
Hi @Priya75 ,
Try using this client script,
function setReferenceFieldValues(sysIds) {
var sysIdArray = sysIds.split(','); // Split the comma-separated string into an array of sys_ids
g_form.setValue('reference_field_name', sysIdArray); // Set the value of the reference field using the array of sys_ids
}
function getReferenceFieldValues() {
var ga = new GlideAjax('MyScriptInclude'); // Create a GlideAjax object
ga.addParam('sysparm_name', 'getSysIds');
ga.getXMLAnswer(function(response) {
if (response) {
setReferenceFieldValues(response);
} else {
alert('Error: No response received from server.');
}
});
}
getReferenceFieldValues(); // Call the function to retrieve sys_ids and set the reference field values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 09:56 PM
Could you please share screenshot of script . to understand better ?
Thanks,
Astik