How to fetch users from roles programatically

  • 16 July 2009
  • 4 replies
  • 2 views

Badge +3

Dear All,


I have a requirement to fetch the users from a role defined in K2 workspace programatically i.e. using K2 APIs.


 I could not get the code to do this. It would be great help if anyone could have done it earlier and share the sample code with me.


Thanks a lot in advance.


 Thanks & Regards


Ajay Gangwar


4 replies

Badge +8

Ajay, here is a code snippet on how it can be done:


(This Code is used in a Server Event, depending on where you use the code, you might get the Connection String from somewhere else)


using SourceCode.Security.UserRoleManager.Management;


.


.


.


.


string conStr = K2.StringTable["SmartObject Server"].Replace(" ","");


Role role = new Role();


UserRoleManager roleManager = new UserRoleManager();


 roleManager.CreateConnection();


roleManager.Connection.Open(conStr);


role = roleManager.GetRole("HR Manager");


verifyUser = role.Include[0].Name.ToUpper();


 

Badge +3

Dear Deon,


 Thanks a lot. It really helped me a lot.


 Thank you very much.


Thanks & Regards


Ajay Gangwar

Badge +3

Hi there,


How to fetch the email address from the roles?


Regards


Amarnath

Badge +8

You can query the AD to get the email addresses using the AD user service object.


Can you state why you need the email address ? when u assign the role as the destination to an activity. their email are resolved at runtime and emails are sent to appropriate users choosing destination user in the mail event

Reply