show the list of email address of all the user

Anjali yadav1
Tera Contributor
var grUser=new GlideRecord('sys_user');
grUser.query();

while(grUser.next())
{
gs.print(grUser.email);
}
 
i run it in background script of PDI but on running i got not authorized as output pls help me to corrected error
5 REPLIES 5

Krushna R Birla
Kilo Sage

Hi @Anjali yadav1 

 

I would suggest you to check your scope first. It should be global. Other than that, you can refer this below code for your reference where I have pushed all the email of users in one array and also printing the count of total emails as shown in below snapshot

 

var emailArr = [];
var grUser = new GlideRecord('sys_user');
grUser.query();
gs.print(grUser.getRowCount());
while (grUser.next()) {
    emailArr.push(grUser.getValue('email'));
}
gs.print(emailArr);

 

KrushnaRBirla_0-1721025107446.png

 

 

This will definitely helps you to resolved your issue. Let me know in case you need anything or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla