On Incident form Auto Populate users email and user id when user changes using script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 12:47 AM
Can anyone know help me to do this coding in Javascript.
trying to do the script with GlideAjax.
I'm tried with the help of getReference method, but we know its not a good practice.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller = g_form.getReference('caller_id');
g_form.setValue('u_email', caller.email);
g_form.setValue('u_user_id', caller.user_name);
}
Thanks in advance.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 12:49 AM
Hi use the below, Make sure field names are correct
Script Include
getUser: function()
{
var user = this.getParameter("sysparm_id");
var userInform ={};
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.query();
if (gr.next()){
userInform.name = gr.getValue("name");
userInform.email = gr.getValue("email");
}
return JSON.stringify(results);
},
Onchange client script on caller id
Script:
var requestor = g_form.getValue("caller_id");
var ga = new GlideAjax("getUserDetails"); // script include name
ga.addParam("sysparm_name", "getUser"); // function name
ga.addParam("sysparm_id", requestor); // value from client script pass to script include
ga.getXMLAnswer(response);
}
}
function response(getResponse) {
var answer = JSON.parse(getResponse);
g_form.setValue("fieldname", answer.name);
g_form.setValue("fieldname", answer.email);
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 12:50 AM
auto Populating the values in a form using glideajax and script include
Let me know if it helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2022 01:05 AM
Hi,
Do you know instead of creating those two fields on incident record, you can bring caller email and caller user id on incident form directly from caller record. You don't need to write any script to populate those values, this way it is easy to maintain data.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
