- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 01:06 AM
Hi,
My mind suddenly stood still.
I have a form: call which has a field company and a field caller.
How to make it so when you choose company, for example "IBM", it will autopopulate the "Caller" field?
The Caller field is a reference field to sys_user and on sys_user there is a field "u_company" that is a reference to the same company table, that the company field on the Call table is.
So when choosing company "IBM" in the Call table, I want to populate Caller field on Call table with the first matching user that has company "IBM" in sys_user table.
Best regards,
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 01:12 AM
Hey,
Most simple solution would probably be an onChange client script for the field "company". Then do a GlideRecord for the sys_user table to return the first user of that company. Should look like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var user = new GlideRecord('sys_user');
user.addQuery('company', newValue);
user.query();
if(user.next())
{
var userID = user.sys_id;
g_form.setValue('caller_id', userID);
}
}
Hope this helps.
Greetings
edit: full client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 01:37 AM
Nevermind the last one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 01:38 AM
Hello,
I have quickly implemented it in my dev instance. I have changed the original answer to the code i used. I can't recreate the issue you seem to have. Try the code i have provided please.
Greetings
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 01:13 AM
You need an onChange Client script and call a glide ajax method to call a script include.
In the glideajax script, do a query on sys_user table based on company, get the first record and return it to client script.
You can find examples in the below link
Examples of asynchronous GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2018 01:20 AM
HI Rody,
I have one question for you.
Any user which comes first for IBM company should be populated in that Caller field Right?
Client script:
It should be onchange of Company;
var abc = new GlideAjax('script include name');
abc.addParm('sysparm_name','function name');
abc.addParm('sysparm_company',newValue);
abc.getXML(xyz);
function xyz(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer); // It will be Sys Id of first user
}
script include:
var Id = this.getParameter('sysparm_company');
var gr = new GlideRecord('sys_user');
gr.addQuery('company',Id);
gr.query();
if(gr.next())
{
return sys_id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2019 06:52 AM
i have requierement of choosing incident state to change whenever i change the incident_task state
can we client script if possible how can