Auto-fill information in several workspace fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 07:50 AM
Hi,
currently I want to fill the fields "email", "mobile_phone", "phone" and "u_employeeid" with information from the sys_user table. The information is supposed to be displayed in the Service Operations Workspace.
I have added the following code to script include:
var UserInformation = Class.create();
UserInformation.prototype = {
initialize: function() {
},
getUserInfo: function(userId) {
var userInfo = {};
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
userInfo.email = userGR.getValue('email');
userInfo.phone = userGR.getValue('phone');
userInfo.mobile_phone = userGR.getValue('mobile_phone');
userInfo.u_mitarbeiternummer = userGR.getValue('u_mitarbeiternummer');
}
return userInfo;
},
type: 'UserInformation'
};
Also, I have created this code for a client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var targetField1 = 'u_string_4';
var targetField2 = 'u_string_1';
var targetField3 = 'u_string_3';
var targetField4 = 'u_string_2';
var userInformation = new GlideAjax('UserInformation');
userInformation.addParam('sysparm_name', 'getUserInfo');
userInformation.addParam('sysparm_user_id', newValue);
userInformation.getXMLAnswer(function(response) {
var userInfo = JSON.parse(response);
if (userInfo.email) {
g_form.setValue(targetField1, userInfo.email);
g_form.setValue(targetField2, userInfo.phone);
g_form.setValue(targetField3, userInfo.mobile_phone);
g_form.setValue(targetField4, userInfo.u_mitarbeiternummer);
} else {
g_form.clearValue(targetField1);
g_form.clearValue(targetField2);
g_form.clearValue(targetField3);
g_form.clearValue(targetField4);
}
});
}
The fields in the workspace are not filled. Where did I go wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 07:54 AM
Hi @Christoph Marku ,
You need to correct your script include method to:
var UserInformation = Class.create();
UserInformation.prototype = {
initialize: function() {
},
getUserInfo: function() {
var userId = this.getParameter('sysparm_user_id');
var userInfo = {};
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
userInfo.email = userGR.getValue('email');
userInfo.phone = userGR.getValue('phone');
userInfo.mobile_phone = userGR.getValue('mobile_phone');
userInfo.u_mitarbeiternummer = userGR.getValue('u_mitarbeiternummer');
}
return userInfo;
},
type: 'UserInformation'
};
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 08:01 AM
Thank you for your response. Unfortunately it did not work. Do you maybe have another suggestion?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 08:04 AM
@Christoph Marku - Make sure your Script Include is Client Callable.
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 08:07 AM
It is, still no change...
Initially, I have started with a client script, looking like the following:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// field names below are from sys_user table and interaction table
var targetField1 = 'u_string_4';
var targetField2 = 'u_string_1';
var targetField3 = 'u_string_3';
var targetField4 = 'u_string_2';
var userGR = new GlideRecord('sys_user');
if (userGR.get(newValue)) {
g_form.setValue(targetField1, userGR.getValue('email'));
g_form.setValue(targetField2, userGR.getValue('phone'));
g_form.setValue(targetField3, userGR.getValue('mobile_phone'));
g_form.setValue(targetField4, userGR.getValue('u_mitarbeiternummer'));
}
else {
g_form.clearValue(targetField1);
g_form.clearValue(targetField2);
g_form.clearValue(targetField3);
g_form.clearValue(targetField4);
}
}
This worked fine in the back end, but not in the workspace. My next thought was to use a script include (as shown above).