java tool process

Confluence User - 05 Aug, 2024

java not running inside the tool process why ? 

here the code the approversList stored from multiselect box multiple values and the firstSelectedValue intilized at the same form with initial value 

i want to store the first approvers inside the firstSelectedValue variable, whats the wrong here, please ?

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.");
        }
    }
}

java;process

2


06 Aug, 2024
confluenceUser
confluenceUser

Hi, I've noticed that you used a type mention for your list "<String>":

List<String> selectedValues = Arrays.asList(fieldValue.split(";"));

For which the Bean Shell does not recognize. See here for more info: Bean Shell Programming Guide#2.Donotneedtomentionthetypeofelementofacollections

It should just be:

List selectedValues = Arrays.asList(fieldValue.split(";"));

Another thing, I've realized that it seems you want to pass a workflow variable value instead, not formdata. Your code is used to get the form values from the database. To pass on wflow variables, see to this kb link: Setting Workflow Variable Value in Process Tool Bean Shell

There's also a plugin tool that you can use for a no-code way in the Joget marketplace: https://marketplace.joget.org/jw/web/userview/mp/mpp/_/vad?id=WVariable_Update_Tool-1

08 Aug, 2024
confluenceUser
confluenceUser

thank you so much 

you help me a lot 

thanks again 

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print