Copy Value from One Field to Another on Form Submission

Introduction

In this guide, you'll learn how to copy the value from one field to another during form submission using Bean Shell. This technique ensures that data entered in one field can be automatically duplicated in another field, streamlining the data entry process and improving user experience. 

How does it work? 

Follow these steps to set up your form and implement the Bean Shell script needed to achieve this.

  1. Choose Bean Shell Form Data Store as the Form's Store Data Store.
  2. Key in the following code.

    import org.joget.apps.app.service.AppUtil;
    import org.joget.apps.form.model.Element;
    import org.joget.apps.form.model.FormRowSet;
    import org.joget.apps.form.model.FormData;
    import org.joget.apps.form.lib.WorkflowFormBinder;
    import org.joget.commons.util.LogUtil;
    import java.sql.Connection;
    import java.sql.SQLException;
    import javax.sql.DataSource;
     
    rows.get(0).setProperty("field2", rows.get(0).getProperty("field1"));
     
    new WorkflowFormBinder().store(element, rows, formData);

    This code copies the value from the form element with the id field1 to field2.

  3. Save the form to apply the changes.
Created by Julieth Last modified by Aadrian on Dec 13, 2024