need to display user email id based on user reference filed

praveen50
Tera Contributor

i have created one catalog item under that created two variable

 

1. add user its referring to sys_user table

2. email id -string name -need to auto populate based on selected user.

 

actually my requirement is to show instead of name I want to show email id in the add user variable or else based on user selection on add user variable need to auto populate on user email in email id variable  .PFA belwo screenshot.

 

can any one help me script

 

find_real_file.png

8 REPLIES 8

And still you want this with combination of Client script and Script include then below is the approach.

 

Write onChange catalog client script on user variable.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax('checkShortDescState');
ga.addParam('sysparm_name', 'checkAvailability');
ga.addParam('sysparm_check', newValue);
ga.getXML(HelloWorldParse);

function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('variable name',answer);

}

}

 

Script include -

name - checkShortDescState

client callable - true

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

checkAvailability:function()
{
var value=this.getParameter('sysparm_check');

var gdt = new GlideRecord('sys_user');
gdt.addQuery('sys_id',value);

gdt.query();
if(gdt.next()){
return gdt.email;
}

} ,

type: 'checkShortDescState'
});

Jaspal Singh
Mega Patron
Mega Patron

Hi Praveen,

 

In case you prefere to show Email address instead of Name then you need to alter the Display Value for the table (not recommended) as it will mean everywhere where User table is referenced will show Email address instead of Name & may not be ideal.

In case you will alternatively you can use ref_ac_columns attribute to show Email as below.

For ge.

ref_auto_completer=AJAXTableCompleter,ref_ac_columns=email,ref_ac_columns_search=true,ref_ac_order_by=name

 

Additionally, if you will to populate the Email field with selected user in the Presenter Email ID variable field then you can use an onChange() client script that runs when Variable1 (Presenter Email ID) field changes as below.

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

  var getusermail=g_form.getReference('variable1',callback); //replace variable1 with proper variablename
 function callback(getusermail)
{
g_form.setValue('variable2',getusermail.email); //replace variable2 with correct variable name
}
   
}

Michael Jones -
Giga Sage

The easiest way to do this is to use a lookup select box for your "Presenter Email ID's" field. Set the table to sys_user and set the Lookup Label and values as email. 

find_real_file.png

 

Then add a variable attribute under the default value tab of is_searchable_choice

 

find_real_file.png

Gives you this: 

find_real_file.png

 

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

praveen50
Tera Contributor

In normal catalog item view below script is working.
In service portal its is not working .
can you help me to written script include & call to script include in catalog client script.