Hi!

I just set up joget workflow on my computer and I need to copy the selection from select box to a read only textfield. I'm new to beanshell. How can I do this?

thanks in advance

EDIT1.:So if I am right this code stores the value from the selectbox in the variable "sbvalue":

import java.util.Collection;
import org.joget.workflow.model.*;
import org.joget.workflow.model.service.*;

WorkflowManager wm = (WorkflowManager) pluginManager.getBean("workflowManager");
String sbvalue ="#formName.fieldName#";     

I suppose i only need to add the value of "firstname" to the read only text field but i did not find anything that helped me.  Also I dont know where toput this code in the form.

5 Comments

  1. Here's one way you might be able to do it.

    Create a form with 2 sections; one has your select box and the other has your read-only text field.

    Edit the section with the text field and under 'Choose Load Binder' (at the top), pick the Bean Shell Form Binder. 

    Click the 'Configure Bean Shell Form Binder' and add your Beanshell code into the Script textarea.

    To get your form variable (for your select box value) you want to use the hash variable #form.formDataTableName.fieldName#. More on Hash Variables here.

    Here's some code that might help you out.

    ApplicationContext ac = AppUtil.getApplicationContext();
    AppService appService = (AppService) ac.getBean("appService");
    String primaryKeyValue="#assignment.processId#";
    //Load the row
    FormRowSet rowSet = appService.loadFormData("myAppId","1","myForm",primaryKeyValue);
    //Get the row data
    FormRow row = rowSet.remove(0);
    String sbvalue = "#form.formDataTableName.fieldName#";
    //Update the field with the value
    row.setProperty("clientFirstname",sbvalue);
    //Add it back in
    rowSet.add(row);
    //Update the table
    appService.storeFormData("myAppId","1","myForm",rowSet,primaryKeyValue);
    
    
    1. I have only one question. To what do  "clientFirstname" and "appService" refer?

      1. "clientFirstname" is the Id of the form field you want to modify.

        "appService" is how the code internally knows how to look up the AppService reference object (so you can use it later in the Bean Shell script.) Behind the scenes, Joget uses the Spring Framework, for among other things, controlling and injecting reference objects. Long story short, you don't need to change that value.

        I haven't tried this, but you might be able to just add the #form.formDataTableName.fieldName# into the value of your read-only field. (I'm not sure when the form fields get saved.) If that works it might be much simpler than writing Bean shell code.

        The third thing you could try which most definitely will work is include some Custom HTML/Javascript into your form to pull the data from the form select box and put it in your read-only field. That might be your best option.

        1. Thank you! You helped me a lot! <3

  2. <form>
        <input type="button"
        value="Kitöltés!"
        onClick='myFunction()'
        />
    </form>

    <script type="text/javascript">
    function myFunction()

    Unknown macro: {    var valtozo = document.getElementById('hrsz_cim');    var irando = document.getElementById('asd');    irando.value = valtozo.value;    }

    </script>

    this ustom html code copies the current value of the field with the id hrsz_cim to a field with an id asd.