Auto populate user details in customized filed on incident table

shaikkhasim
Tera Contributor

Hi Team

i have created a custom filed on incident form-- filed name is (u_t_id).. need to auto populate caller details in that filed 

i have used client script on load, but it shows un identified 

 

client script on load 

function onLoad() {
   //Type appropriate comment here, and begin script below

   var d=g_user.userID;
   g_form.setValue("caller_id",d);
   var c1=g_form.getValue("caller_id");
   g_form.setValue("u_t_id",c1.user_name);
 
Regards
Khasim

 

 

khasim
6 REPLIES 6

Hi Ankuar

The field is string type only 

i am getting caller id details , while form is loaded..

let me try on change client script on caller id 

Regards

khasim

 

 

 

khasim

pethumdesilva
Tera Guru

Hi @shaikkhasim 

 

Create a client callable script include and use it in onload or onchange of caller

 

Client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// if (isLoading || newValue === '') {
// return;
// }


var ga1 = new GlideAjax('FetchUser');
ga1.addParam('sysparm_name', 'getUser');
ga1.addParam('sysparm_user', pass user id here);
ga1.getXMLAnswer(setValues);

 

function setValues(response) {
var user = JSON.parse(response);
g_form.setValue('u_manager', user.manager);
g_form.setValue('u_username', user.username);
g_form.setValue('u_email', user.email);
}
}

Script include

var FetchUser = Class.create();
FetchUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getUser: function() {
var user = this.getParameter('sysparm_user');
var obj = {};

var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', user);
usr.query();
if (usr.next()) {
obj.manager = usr.manager.getDisplayValue();
obj.username = usr.user_name.getDisplayValue();
obj.email = usr.email.getDisplayValue();
}
return JSON.stringify(obj);
},

type: 'FetchUser'
});

 

Best regards,

Pethum