Get a form reference field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 04:21 AM
Hello Team,
I am trying to get a form reference field value; According to my selection from the lookup, one other field should auto populate. Can someone please help me rectify this script? (Using Glide Record on On Change Client Script)
var entity = g_form.getValue("business_unit");
var gr= new GlideRecord('cmdb_ci_business_process');
gr.addQuery('parent',entity);
gr.query();
while(gr.next()){
g_form.setValue('u_service_name',gr.name);
g_form.setValue('applies_to',gr.u_associate_process);
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 04:35 AM
This is to inform you that You cannot use GlideRecord object in client side scripting.
This will work only in Server side scripting like Business rules, script includes, scheduled jobs...
For Your use case you need to do GlideAjax call from the client script and create a new Script Include which is client callable and do the GlideRecord query there and return the required value.
The returned value need to be setup in the form.
Client Script: -
var entity = g_form.getValue("business_unit");
var gr= new GlideRecord('cmdb_ci_business_process');
gr.addQuery('parent',entity);
gr.query();
while(gr.next()){ /// If this query returns only 1 record than prefer to use if() not while()
return gr.u_associate_process;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 04:36 AM
Please accept the solution and mark helpful if this answers your question