I'm trying trying to create a user, which work like a charm. But I cannot assign he/she a userlicense. I get the error message. Field ObjectId has not been loaded or set. What Field ObjectId has not been set?
User user = new User(_sessionHelper.getSession());
user.setName(importResourcesData.getSsoID());
user.setPersonalName(importResourcesData.getFirstName() + " " + importResourcesData.getLastName());
User.setEmailAddress(importResourcesData.getEmailAdress());
user.setPassword(importResourcesData.getSsoID(), importResourcesData.getSsoID());
user.setAllResourceAccessFlag(false);
user.setGlobalProfileObjectId(getDefaultGlobalSecurityProfile());
ObjectId userId = user.create(); //WORKS!!!
BOIterator<UserLicense> loadResources = _sessionHelper.getElm().loadUserLicenses(new String[]{"LicenseType"}, "LicenseType = 'Timesheets'", null);
Userlicense ul = loadResources.next();
//This Fails!
user.createUserLicense(ul);