Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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
*/

var ReferenceQualifierAjaxHelper = Class.create();
ReferenceQualifierAjaxHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserInformation : function() {
var userID = this.getParameter('sysparm_user');
var userRec = new GlideRecord('sys_user');

if(userRec.get(userID)) {
var results = {
"email" : userRec.getValue('email'),
"department" : userRec.getValue('department'),
"title" : userRec.getValue('title'),
"phone" : userRec.getValue('phone')
};

return JSON.stringify(results)
}

},

type: 'ReferenceQualifierAjaxHelper'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Overview
This onchange catalog client script and script inlcude work together autopopulate the user fields that might show up on a catalog item. In the
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.
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
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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
* already autopopulates the logged in user with its OOB functionality. In the updateUserFields function you can add any other user fields
* that you might need.
*/

function onChange(control, oldValue, newValue, isLoading) {
//This variable will store the sys_id of the user that populates in your requested for variable
var userID = newValue;

var ga = new GlideAjax(ReferenceQualifierAjaxHelper);
ga.addParam('sysparm_name', 'getUserInformation');
ga.addParam('sysparm_user', userID);
ga.getXMLAnswer(updateUserFields);

function updateUserFields(response) {
var returnedData = JSON.parse(response);
g_form.setValue("email", returnedData.email);
g_form.setValue("department", returnedData.department);
g_form.setValue("title", returnedData.title);
g_form.setValue("phone", returnedData.phone);
}
}
Loading