Skip to content

Instantly share code, notes, and snippets.

@jverweijL
Last active January 7, 2020 16:07
Show Gist options
  • Save jverweijL/c2ae19cecfd61d775e1a6189bbc254b2 to your computer and use it in GitHub Desktop.
Save jverweijL/c2ae19cecfd61d775e1a6189bbc254b2 to your computer and use it in GitHub Desktop.
Add new user to Liferay using Liferay Forms and Workflow
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.counter.kernel.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.service.UserLocalServiceUtil;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.dynamic.data.lists.service.DDLRecordVersionLocalServiceUtil;
import com.liferay.dynamic.data.lists.model.DDLRecordVersion;
// static stuff
long ADMIN_ID = 20130L;
// Fetch the form record Id from the workflow context
long recVerId = GetterUtil.getLong((String)workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
System.out.println("recVerId: " + recVerId);
DDLRecordVersion ddlRecordVersion = DDLRecordVersionLocalServiceUtil.getLatestRecordVersion(recVerId);
// let's make sure it's initiated
System.out.println("*** creating user from workflow ***");
// get the companyID
long companyId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
System.out.println("companyID: " + companyId);
// get the servicecontext
ServiceContext serviceContext = (ServiceContext) workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
long userId = CounterLocalServiceUtil.increment();
System.out.println("New userId: " + userId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment