Skip to content

Commit 329be68

Browse files
authored
Autopopulate user info on the Employee Center (#2634)
* Create onChangeClientScript.js * Create ClientCallableScriptInclude.js * Updated onChangeClientScript.js removed location and added department field instead * Create README.md
1 parent 7f50ab1 commit 329be68

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* The following is a client callable script include. This can be used with the onChange Client script to be able to gather the data on the server side
3+
*/
4+
5+
var ReferenceQualifierAjaxHelper = Class.create();
6+
ReferenceQualifierAjaxHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
7+
getUserInformation : function() {
8+
var userID = this.getParameter('sysparm_user');
9+
var userRec = new GlideRecord('sys_user');
10+
11+
if(userRec.get(userID)) {
12+
var results = {
13+
"email" : userRec.getValue('email'),
14+
"department" : userRec.getValue('department'),
15+
"title" : userRec.getValue('title'),
16+
"phone" : userRec.getValue('phone')
17+
};
18+
19+
return JSON.stringify(results)
20+
}
21+
22+
},
23+
24+
type: 'ReferenceQualifierAjaxHelper'
25+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Overview
2+
This onchange catalog client script and script inlcude work together autopopulate the user fields that might show up on a catalog item. In the
3+
global scope you will have to create the client callable script include to be able to use the Ajax call that is in the on change client script.
4+
In this example we use the OOB Requested For field that already auto populates the user that is logged in then we go to the server to get that
5+
users information. The fields that are brough back are the ones that are in the code but you can modify to bring back more or less fields if needed.
6+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* In order for this to work make sure to have an onChange catalog client script on a variable that is type Requested For. This variable
3+
* already autopopulates the logged in user with its OOB functionality. In the updateUserFields function you can add any other user fields
4+
* that you might need.
5+
*/
6+
7+
function onChange(control, oldValue, newValue, isLoading) {
8+
//This variable will store the sys_id of the user that populates in your requested for variable
9+
var userID = newValue;
10+
11+
var ga = new GlideAjax(ReferenceQualifierAjaxHelper);
12+
ga.addParam('sysparm_name', 'getUserInformation');
13+
ga.addParam('sysparm_user', userID);
14+
ga.getXMLAnswer(updateUserFields);
15+
16+
function updateUserFields(response) {
17+
var returnedData = JSON.parse(response);
18+
g_form.setValue("email", returnedData.email);
19+
g_form.setValue("department", returnedData.department);
20+
g_form.setValue("title", returnedData.title);
21+
g_form.setValue("phone", returnedData.phone);
22+
}
23+
}

0 commit comments

Comments
 (0)