- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2021 09:01 AM
Hello, Requesters would be selecting the users using List Collector and requirement is to copy the email addresses of selected users with comma separated (Right Side of List collector) to another variable (Multi Line Text Variable). Text Variable to make it read only and visible to Fulfillers.
I have tried creating script by looking some past examples but seems its not working. Any suggestions on what seems to be wrong please
Variable Details:
Client Script
Type - onChange, Variable Name - select_users //list collector variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue === '') {
g_form.clearValue('copied_from_list');
}
var gaPhone = new GlideAjax('getEmailAddress');
gaPhone.addParam('sysparm_name', 'get_email');
gaPhone.addParam('sysparm_users', newValue);
gaPhone.getXMLAnswer(_handleResponse);
function _handleResponse(response) {
var answer = response;
g_form.setValue('copied_from_list', answer);
}
}
Script Include - Client Callable: Checked
var getEmailAddress = Class.create();
getEmailAddress.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get_email : function() {
var userArr = this.getParameter('sysparm_users').split(',');
var emailArr = [];
for(var i = 0; i < userArr.length; i++) {
var grUser = new GlideRecord('sys_user');
if(grUser.get(userArr[i])) {
emailArr.push(grUser.getValue('email'));
}
}
emailArr.join();
return emailArr.toString();
},
type: 'getEmailAddress'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 06:39 AM
Hi Vinay,
then you can use Run Script in the workflow of catalog item
Updated: to remove current.update()
var userArr = current.variables.select_users.toString().split(',');
var emailArr = [];
for(var i = 0; i < userArr.length; i++) {
var grUser = new GlideRecord('sys_user');
if(grUser.get(userArr[i].toString())) {
emailArr.push(grUser.getValue('email'));
}
}
var values = emailArr.join();
current.variables.copied_from_list = values;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 07:03 AM
Hi Vinay,
Did you accidentally mark other response as correct.
Would you mind marking my response as correct if I was able to help/guide you.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 07:25 AM
Both the responses were helpful. I did modified and removed the current.update from Run Script step from workflow. Thanks both. I have modified and made one answer helpful and other one correct. Thanks both.