- 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 06:11 AM
Hi,
Can you explain this
1) This shouldn't be visible while submitting. - So are you saying it is fine if you update the multi-line text variable post RITM submission
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 06:19 AM
Yes, should be fine to populate post RITM submission, This field is not necessary for requesters, Fulfillers to use this field to copy the data selected in List collector variables by users.
- 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 06:50 AM
Okay, then use the Run script activity and the script provided by Ankur but a little modification as current.update() should not be used in Run script activity.
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2021 06:55 AM
Thank you All, This works fine.