We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

comma seperated email in servicenow script

deepika46
Tera Contributor

Hello experts,

 

consider  variable 'a' storing the values

a=

39b052153737560039ad04e954990e47,d10f98a41bc00c90326698271d4bcbf8

a stores the sysid of users. It can store 1,2 , n number of sysids;

 

I need to create variable which will store the email ids of the users defined in variable a

 

Output will be:

abc@gmail.com,xyz@gmail.com(to give the email id comma seperated of the sys_ids that are coming in variable a)

 

 

Is there any script we can use to store these values

 

I am new to ServiceNow Scripting so any help would be really appreciated

 

Thanks in advance

1 ACCEPTED SOLUTION

hvrdhn88
Giga Patron

@deepika46 

You can try to use below script . this is just an example. make changes based on your need. 

 

var a = '62826bf03710200044e0bfc8bcbe5df1,a8f98bb0eb32010045e1a5115206fe3a,0a826bf03710200044e0bfc8bcbe5d7a'
var arr = [];
var op = a.split(',');

for(var i = 0; i <op.length ; i++){
	var grs = new GlideRecord('sys_user');
	grs.addQuery('sys_id',op[i]);
	grs.query();
	while(grs.next())
	arr.push(grs.getValue('email'));
}

gs.print(arr.join(','));

 

 

Thanks,

Harsh

View solution in original post

1 REPLY 1

hvrdhn88
Giga Patron

@deepika46 

You can try to use below script . this is just an example. make changes based on your need. 

 

var a = '62826bf03710200044e0bfc8bcbe5df1,a8f98bb0eb32010045e1a5115206fe3a,0a826bf03710200044e0bfc8bcbe5d7a'
var arr = [];
var op = a.split(',');

for(var i = 0; i <op.length ; i++){
	var grs = new GlideRecord('sys_user');
	grs.addQuery('sys_id',op[i]);
	grs.query();
	while(grs.next())
	arr.push(grs.getValue('email'));
}

gs.print(arr.join(','));

 

 

Thanks,

Harsh