Set value in reference field glide ajax

Priya75
Tera Contributor

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);

 

7 REPLIES 7

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.

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

Deepak Shaerma
Kilo Sage

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