Populate values in multi line text field from a table.

aastha3
Giga Contributor

I have multi line field on my catalog in which I need values populated from a table . There is a field "user" in my table which should be mapped to "requested for" field in catalog form.

If both the fields (user == requested for ) matches then I need to display the rest of the field values from the table for that user in the multi line text field in my catalog form.

Please guide how this can be done.

1 ACCEPTED SOLUTION

guhann
Mega Guru

1) Create an onChange Client Script on the requested_for variable with below code



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }



  var ga = new GlideAjax('UserInfoUtils');


  ga.addParam('sysparm_name','getUserInfo');


  ga.addParam('sysparm_user',newValue);


  ga.getXML(getInfo);



  function getInfo(response) {


  var info = response.responseXML.documentElement.getAttribute('answer');


  g_form.setValue('multi_line_text_variable_name',info);


  }



2) Create a script include as below.


Name: UserInfoUtils


Client callable: true


script:


var UserInfoUtils= Class.create();


UserInfoUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  getUserInfo : function()


  {


  var info = '';


  var grUser = new GlideRecord('table_name');


  grUser.addQuery('sys_id', this.getParameter('sysparm_user'));


  grUser.query();


  if(grUser.next())


  {


  info += 'Label1 : ' + grUser.field_name1 + '\n';


  info += 'Label2 : ' + grUser.field_name2 + '\n';


.........


........


  }


  return info.toString();


  },



  type: 'UserInfoUtils'


});


View solution in original post

2 REPLIES 2

guhann
Mega Guru

You can have an onChange catalog client script on the variable 'Requested for' in which you have to check if the selected requested_for user exists in ur table. If exist, then fetch all the other values of that user record and populate it in multi text field.


guhann
Mega Guru

1) Create an onChange Client Script on the requested_for variable with below code



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }



  var ga = new GlideAjax('UserInfoUtils');


  ga.addParam('sysparm_name','getUserInfo');


  ga.addParam('sysparm_user',newValue);


  ga.getXML(getInfo);



  function getInfo(response) {


  var info = response.responseXML.documentElement.getAttribute('answer');


  g_form.setValue('multi_line_text_variable_name',info);


  }



2) Create a script include as below.


Name: UserInfoUtils


Client callable: true


script:


var UserInfoUtils= Class.create();


UserInfoUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  getUserInfo : function()


  {


  var info = '';


  var grUser = new GlideRecord('table_name');


  grUser.addQuery('sys_id', this.getParameter('sysparm_user'));


  grUser.query();


  if(grUser.next())


  {


  info += 'Label1 : ' + grUser.field_name1 + '\n';


  info += 'Label2 : ' + grUser.field_name2 + '\n';


.........


........


  }


  return info.toString();


  },



  type: 'UserInfoUtils'


});