Skip to content

Commit ba8b6ba

Browse files
committed
Client side
1 parent 1241a41 commit ba8b6ba

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Call Script Include to recover User data
2+
3+
In this onChange Client Script, the scenario is this:
4+
- In a form, we have a reference field to the User table to allow our user to select any user within the platform.
5+
- Once a user is selected, we are passing that Sys ID to recover more information regarding the selected record.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Type: onChange
3+
Field: a reference to the User table
4+
*/
5+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
6+
if (isLoading || newValue === '') {
7+
return;
8+
}
9+
10+
var test = newValue;
11+
12+
//The Script Include called here can be found in:
13+
//Server-Side Components / Script Includes / Get User Data by Id
14+
//It is in Global scope
15+
var ga = new GlideAjax('GetUserData');//script include name
16+
ga.addParam('sysparm_name', 'GetUserBy_id'); //method to be called
17+
ga.addParam('sysparm_userid', test); //send a parameter to the method.
18+
ga.getXMLAnswer(userInfoParse);
19+
20+
function userInfoParse(response) {
21+
if (response == '') {
22+
g_form.addErrorMessage('User not found with the informed sys_id.');
23+
} else {
24+
//alert(response);
25+
var obj = JSON.parse(response);
26+
g_form.setValue('u_first_name', obj.first_name.toString());
27+
g_form.setValue('u_last_name', obj.last_name.toString());
28+
g_form.setValue('u_email', obj.email.toString());
29+
}
30+
31+
}
32+
33+
}

0 commit comments

Comments
 (0)