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
06-06-2024 01:07 PM
Sharing screenshots of configurations is fine, but a screenshot of code is NOT the best idea.
Paste it in as code: TNT: Screenshots Help, but Code is Better. And make sure it is formatted so it is easier to read: TNT: And Formatted Code is Even Better.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 01:14 PM
Did you solve your issue? You mentioned it was a Reference field that you were trying to populate, but you are returning a comma-separated list of sys_ids? Is the field of type List instead of Reference?
And when you are populating a Reference field in a Client Script, you want to use getValue() with 3 parameters to avoid a return back to the server: ServiceNow Client-Side API Reference.
Take a look at this post for more info: TNT: Returning Data from GlideAjax Calls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2024 10:16 PM
Hello @Priya75
Make sure in the Script include the response is in JSON and passing the sys id -
return JSON.stringify(result);
and call in client side like this:
var answer = JSON.parse(response);
var sysId = answer.sys_id;
g_form.setValue("field_name", sysId);
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma