Catalog client script to get requested for value

Deepa12
Tera Contributor

Hi,

Pls assist me to get the requested for value which is displaying into order submission page. 

I want to generate the user account name depands on requested for value like adminXXX(admin + requested for userid).

I understand that requested for field value fetch the currently logged in user name but if i update any other user name while order submission window, i want to capture the value of requested for field current(latest) value. pls assist to script requested for field latest value. Thanks.

1 REPLY 1

Sumanth16
Kilo Patron

Hi @Deepa12 ,

 

You can achieve your requirement using Script Include and GlideAjax. I tried in my personal instance and working absolutely very good for your reference i am posting my code make change as per your field names .

Script Include:

var user_name = Class.create();
user_name.prototype = Object.extendsObject(AbstractAjaxProcessor, {
username:function()
{
	var sys_id=this.getParameter('sysparam_sys');
	var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',sys_id);
gr.query();
	if(gr.next())
	{
		return gr.first_name+" "+gr.last_name;
	}
},
    type: 'user_name'
});

Onchange Client Script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;}
   var usersys=g_form.getValue('requested_for');
   var ga = new GlideAjax('user_name');
    ga.addParam('sysparm_name', 'username');
    ga.addParam('sysparam_sys', usersys);
    ga.getXML(callBackFunction);
    function callBackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('user_name', answer);}}

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda