How do I get User Email from External Directory

Confluence User - 12 Jan, 2023

I want User email From The External directory 
I only Get user name and full name 
is There any option to get user email from the external directory 


user;forms;datalists;userviews

4


12 Jan, 2023
confluenceUser
confluenceUser

Hi,

-You can use "BeanShell Form Binder"

-After setting up the user's info, you can use the BeanShell script below and modify it to your convenience.

Script:

import java.util.Collection;
import org.joget.apps.app.service.AppUtil;
import org.joget.apps.form.model.Element;
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.model.FormRow;
import org.joget.apps.form.model.FormRowSet;
import org.joget.apps.form.service.FormUtil;
import org.joget.directory.model.User;
import org.joget.directory.model.service.ExtDirectoryManager;
 
public FormRowSet load(String[] values) {
    FormRowSet rows = new FormRowSet();
     
    ExtDirectoryManager directoryManager = (ExtDirectoryManager) AppUtil.getApplicationContext().getBean("directoryManager");
     
    //set groupId based on dependency value
    String groupId = "G-004";
    if (values != null && values.length > 0) {
        groupId = values[0];
    }
     
    //Get users using directory manager
    Collection userList = directoryManager.getUsers(null, null, null, null, groupId, null, null, "firstName", false, null, null);
    for(Object u : userList){
        User user = (User) u;
        FormRow option = new FormRow();
        option.setProperty(FormUtil.PROPERTY_VALUE, user.getUsername());
        option.setProperty(FormUtil.PROPERTY_LABEL, user.getFirstName() + " " + user.getLastName() + " " + user.getEmail());
        rows.add(option);
    }
     
    return rows;
}
 
//call load method with injected variable
return load(values);

Output Preview:

See Bean Shell Programming Guide#Usages for more information. Thank you

13 Jan, 2023
confluenceUser
confluenceUser

I had copy this code on the form
but  I don't get any user  email from the external directory 

Thanx in advance

16 Jan, 2023
confluenceUser
confluenceUser

Check the group id for your users in the external directory. Provide that group id in the variable "String groupId = "G-004". THank you

16 Jan, 2023
confluenceUser
confluenceUser

Or set "String groupId = "null";.Thank you

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print