public void handleMultiSelectField(FormData formData, FormService formService) { // Get the multi-select field value from form data String multiSelectFieldName = "approversList"; String fieldValue = formData.getFieldValue(multiSelectFieldName);
if (fieldValue != null && !fieldValue.isEmpty()) { // Split the field value by semicolons to get a list of selected values List<String> selectedValues = Arrays.asList(fieldValue.split(";"));
if (!selectedValues.isEmpty()) { // Get the first selected value String firstSelectedValue = selectedValues.get(0);
// Store or use the first selected value as needed // For example, set it as a new value in the form data formData.getFieldValues().put("firstSelectedApprover", firstSelectedValue);
// Optionally, log or further process the firstSelectedValue LogUtil.info(MultiSelectHandler.class.getName(), "First Selected Approver: " + firstSelectedValue); } else { LogUtil.info(MultiSelectHandler.class.getName(), "No values found after splitting."); } } else { LogUtil.info(MultiSelectHandler.class.getName(), "No values found in approversList."); } } }
i put this java code inside tool process but it is not working, what is the reason ?
note: the firstSelectedValue is a process variable like approversList(come from multiselected box, multiple values), i want to store inside firstSelectedValue the first approver from approversList, the firstSelectedValue i have initialized it inside the from and give it a default value, so i want to save the first approver inside this variable as the code show but the code is not running why ? is there any library i should install or something ?
import org.joget.apps.form.model.FormData;
import org.joget.apps.form.service.FormService;
import org.joget.commons.util.LogUtil;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class MultiSelectHandler {
public void handleMultiSelectField(FormData formData, FormService formService) {
// Get the multi-select field value from form data
String multiSelectFieldName = "approversList";
String fieldValue = formData.getFieldValue(multiSelectFieldName);
if (fieldValue != null && !fieldValue.isEmpty()) {
// Split the field value by semicolons to get a list of selected values
List<String> selectedValues = Arrays.asList(fieldValue.split(";"));
if (!selectedValues.isEmpty()) {
// Get the first selected value
String firstSelectedValue = selectedValues.get(0);
// Store or use the first selected value as needed
// For example, set it as a new value in the form data
formData.getFieldValues().put("firstSelectedApprover", firstSelectedValue);
// Optionally, log or further process the firstSelectedValue
LogUtil.info(MultiSelectHandler.class.getName(), "First Selected Approver: " + firstSelectedValue);
} else {
LogUtil.info(MultiSelectHandler.class.getName(), "No values found after splitting.");
}
} else {
LogUtil.info(MultiSelectHandler.class.getName(), "No values found in approversList.");
}
}
}
i put this java code inside tool process but it is not working, what is the reason ?
note: the firstSelectedValue is a process variable like approversList(come from multiselected box, multiple values), i want to store inside firstSelectedValue the first approver from approversList, the firstSelectedValue i have initialized it inside the from and give it a default value, so i want to save the first approver inside this variable as the code show but the code is not running why ? is there any library i should install or something ?