Variable attribute to show email id from username in list collector

Bhuvanesh Babu
Giga Expert

Hi Team, 

I need display auto populate email ids in the List Collector of a the users selected in another List collector in Portal.

I achieved this using Script include and Client script.

but can someone help me to show the email id instead of name in Signer email if Field using variable attributes in the variable

find_real_file.png

find_real_file.png

Script Include

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

getEmailid: function() {
var signeremail = this.getParameter('sysparm_signeremail');
var users = signeremail.split(','); // splits the answer by the de-limiter ","
var str = '';

for (var i = 0; i < users.length; i++) {

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", users[i]);
gr.query();
if (gr.next()) {
// str = str + gr.email + ',';
str = gr.sys_id;

}
}
return str;
},

type: 'getSigneremailid'
});

 

Catalog Client Script

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getSigneremailid'); //call script Include
ga.addParam('sysparm_name', 'getEmailid'); //call Required function within Script Include
ga.addParam('sysparm_signeremail', newValue);
ga.getXML(callback);

function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != null) {
g_form.setValue("signer_email", answer); // sets value to the field in the portal
} else if (answer == null) {
g_form.setValue("signer_email", '');
}
}
}

 

Regards,

babu

1 ACCEPTED SOLUTION

I'm not aware of a variable attribute that allows this Service catalog variable attributes | ServiceNow Docs

You'll either need to use a string field or forgo the idea. What's the reason for duplication? You've got the users, why do you need to have a second box for their email addresses.

View solution in original post

4 REPLIES 4

Anil Lande
Kilo Patron

Hi,

If your variable Signer Email is referring to the 'sys_user' table then it will only show User Name as display value. As it is ServiceNow's OOB behavior. A table can have only one display value at a time.

Anyway, if you are auto-populating second field nbased on selection of first field then I would suggest you to make it 'Single Line Text' instead 'List Collector'. You can populate it with same client script, just return email of user instead sys_id.

 

Note: Also you have to apply logic to get all users emails in coma separated string in case of multiple selection.

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@Kieran Anson @Anil Lande 

Hi Anil & Kieran Anson,

 
I did explain that here but the requirement is that it should be a List collector.

I need to somehow show the email id auto populated in "Signer email(s)" field in portal alone, 
 in the background ticket it can be names.

when googled and searched in community all I found was to use Variable attributes, which I am not aware of.

 

find_real_file.png

 

Regards, 

Babu

I'm not aware of a variable attribute that allows this Service catalog variable attributes | ServiceNow Docs

You'll either need to use a string field or forgo the idea. What's the reason for duplication? You've got the users, why do you need to have a second box for their email addresses.

Kieran Anson
Kilo Patron

List collectors, similar to a reference field, use a display value that is per table and can't be overridden on a use case basis.

What you could do is set the signer names field to a string field and populate it as a comma separated field.