I have a requirement where I need to send mail to all users with the admin role for that I need list of users of an Admin role on that application.

Can anyone help me with this?

Hi Gandeev,

You must have a table that will be the extension of the Users table, where the roles of each user are defined, and you can send to the output of that list filtered by the role you want.


Other solution:

Any group created in Users application (<yourserver>/Users) will be stored in the entity Group.
Than you have the entity Group_Role, that holds the association between groups and roles, and the entity Group_User, that holds the association between groups and users.

But, if you just need to select users based on ROLE, you just need to use User_Effective_Role.
This entity holds all the EFFECTIVE roles. The User_Role entity holds only the roles applied direct to users, not through groups.


You're joining two tables by "not joining them". You're saying "User_Effective_Role" only with "User" but then your join condition should be "User.Id" = "User_Effective_Role.UserId" and:

  • Either you filter out with a condition like "User_Effective_Role"."Role_Id" = Roles.Admin or
  • You use "User.Id" = "User_Effective_Role.UserId" and "User_Effective_Role".RoleId = Roles.Admin on your join condition


Cheers,

Nuno Verdasca

Nuno Miguel Verdasca wrote:

Hi Gandeev,

You must have a table that will be the extension of the Users table, where the roles of each user are defined, and you can send to the output of that list filtered by the role you want.


Other solution:

Any group created in Users application (<yourserver>/Users) will be stored in the entity Group.
Than you have the entity Group_Role, that holds the association between groups and roles, and the entity Group_User, that holds the association between groups and users.

But, if you just need to select users based on ROLE, you just need to use User_Effective_Role.
This entity holds all the EFFECTIVE roles. The User_Role entity holds only the roles applied direct to users, not through groups.


You're joining two tables by "not joining them". You're saying "User_Effective_Role" only with "User" but then your join condition should be "User.Id" = "User_Effective_Role.UserId" and:

  • Either you filter out with a condition like "User_Effective_Role"."Role_Id" = Roles.Admin or
  • You use "User.Id" = "User_Effective_Role.UserId" and "User_Effective_Role".RoleId = Roles.Admin on your join condition


Cheers,

Nuno Verdasca

Hi Verdasca 

Thank you for the input I have added User_role and role entities and through that, I'm able to get all users with admin access but I don't know how can I send mail to all emails  which I retrieved 


Hi Gandeev,

The email is on the Users table. If you already have them, you should do a for each on the list of Users returned by the query/aggregate and use the Send Email widget.

Something like that:

For this to work, you must be sure that the SMPT is configured on the service center. 

If you need help with this, use the links that Nuno provided.

Hi Gandeev,

You can do sending mails without creating other entities.

GetUsers Aggregate -> For Each Loop by GetUsers.List -> If Statement with condition CheckAdminRole(GetUsers.List.Current.User.Id). False branch connect back to For Each, True Branch to Send Email, and Send Email to For Each

Hi Gandeev,

1. You need to create an aggregate to get the data(the list of users you need to send an email). 

2. You need to iterate that aggregate if it has 1 or more records. So you will need a For Each for that

3. Use the send email tool inside you for each so that each records on that aggregate will receive an email.

I Gandeev,


That solution of "For each in sending email" approach can give you problems (in the future, that emails can be seen as spam), and, has less performance that it can have.

You can build a string (in a local variable) with all emails separated with a comma and insert that string in the email "To" field.


Best regards,

Ricardo Pereira