private void assignmentSubmit() {
ApplicationContext ac = AppUtil.getApplicationContext();
AppService appService = (AppService) ac.getBean("appService");
FormService formService = (FormService) ac.getBean("formService");
WorkflowManager workflowManager = (WorkflowManager) ac.getBean("workflowManager");
String activityId = getRequestParameterString("activityId");
if (isAssignmentExist(activityId)) {
try {
WorkflowAssignment assignment = workflowManager.getAssignment(activityId);
// set process instance ID as primary key
FormData formData = new FormData();
formData = formService.retrieveFormDataFromRequestMap(formData, getRequestParameters());
String processId = assignment.getProcessId();
// get form
String formUrl = getUrl() + "?_action=assignmentSubmit&activityId=" + activityId;
PackageActivityForm activityForm = appService.viewAssignmentForm(getRequestParameterString("appId"), getRequestParameterString("appVersion"), activityId, formData, formUrl);
Form form = activityForm.getForm();
// submit form
FormData formResult = formService.executeFormActions(form, formData);
// check for validation errors
if (formResult.getFormResult(AssignmentWithdrawButton.DEFAULT_ID) != null) {
// withdraw assignment
workflowManager.assignmentWithdraw(activityId);
} else if (formResult.getFormResult(AssignmentCompleteButton.DEFAULT_ID) != null) {
// complete assignment
Map<String, String> variableMap = AppUtil.retrieveVariableDataFromMap(getRequestParameters());
formResult = appService.completeAssignmentForm(form, assignment, formData, variableMap);
Map<String, String> errors = formResult.getFormErrors();
if (!formResult.getStay() && errors.isEmpty() && activityForm.isAutoContinue()) {
setAlertMessage(getPropertyString("messageShowAfterComplete"));
// redirect to next activity if available
WorkflowAssignment nextActivity = workflowManager.getAssignmentByProcess(processId);
if (nextActivity != null) {
setProperty("view", "redirect");
setProperty("messageShowAfterComplete", "");
String redirectUrl = getUrl() + "?_action=assignmentView&activityId=" + nextActivity.getActivityId();
setAlertMessage("");