User created programmatically doesn't show in Control panel

8ヶ月前 に David H Nebinger によって更新されました。 New Member 投稿: 1 参加年月日: 24/11/04 最新の投稿

Hi Everyone!

I'm using Liferay CE 7.4.3-112 version and I'm trying to create a custom job, that adds users to Liferay. My problem is, that after adding user with 

UserLocalServiceUtil.addUserWithWorkflow() or addUser() 

the user gets created in the database, but it is not showing in the Control Panel->Users and Organizations panel, not even after reindexing everything. The created user in the database seems exactly the same as users before, that are showing just fine.

Here is my code for adding the user:

String randomPassword = UUID.randomUUID().toString();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setCompanyId(20098);
serviceContext.setUserId(_configuration.userId());
serviceContext.setAddGuestPermissions(true);
serviceContext.setIndexingEnabled(true);
User user;
try{
    user = UserLocalServiceUtil.addUserWithWorkflow(
            _configuration.userId(), // e.g., default company admin userId
            20098,
            false, // autoPassword = false
            randomPassword,
            randomPassword,
            false, // autoScreenName = false
            "john.doe", //screenName
            "john.doe@example.com", //emailAddress
            LocaleUtil.getDefault(),
            "John", // first name
            "", // middle name
            "Doe", // last name
            0, 0, true, // prefix/suffix/male
            1, 26, 2002, // birthday, month, day, year
            "Developer", // job title
            AzureLiferayUserSyncPortletKeys.AZUREUSERTYPE,
            null, // List of group IDs
            null, // List of organization IDs
            null, // List of role IDs
            null, // List of user group IDs
            false, // sendEmail
            serviceContext // ServiceContext
    );

} catch (Exception e) {
    throw new RuntimeException(e);
}

I don't really understand the what the ServiceContext do in this scenario, the things I set are mainly from other forum posts in a similar context. I'm new to Liferay development, please help.

thumbnail
5ヶ月前 に Nikhil Nishchal によって更新されました。 Regular Member 投稿: 179 参加年月日: 12/06/22 最新の投稿

Hi Illés Ákos,
Service context you can create and add there. Could you please match created user data with existing user in DB like group id , company id etc.
Also, Please enable the log to get if there is any exception.

Thanks!