Hello,

I want to retrieve and set form data from within the BeanShell plugin. How can I do this? I found an old article in the v2 knowledgebase that refers to a FormManager class, however this class doesn't seem to exist anymore in the v3.

Thanks in advance,

Andrew

  • No labels

4 Comments

  1. Hi Andrew,

    You can use the API exist in AppService

    /**
         * Use case for form submission by ID
         * @param formDefId
         * @param formData
         * @param ignoreValidation
         * @return
         */
        FormData submitForm(String appId, String version, String formDefId, FormData formData, boolean ignoreValidation);
    
        /**
         * Load specific data row (record) by primary key value
         * @param appId
         * @param version
         * @param formDefId
         * @param primaryKeyValue
         * @return null if the form is not available, empty FormRowSet if the form is available but record is not found.
         */
        FormRowSet loadFormData(String appId, String version, String formDefId, String primaryKeyValue);
    
        /**
         * Load specific data row (record) by primary key value for a specific form
         * @param form
         * @param primaryKeyValue
         * @return null if the form is not available, empty FormRowSet if the form is available but record is not found.
         */
        FormRowSet loadFormData(Form form, String primaryKeyValue);
    
        /**
         * Method to load specific data row (record) by primary key value for a specific form.
         * This method is non-transactional to support hibernate's auto update of DB schemas.
         * @param form
         * @param primaryKeyValue
         * @return null if the form is not available, empty FormRowSet if the form is available but record is not found.
         */
        FormRowSet loadFormDataWithoutTransaction(Form form, String primaryKeyValue);
    
        /**
         * Store specific data row (record).
         * @param appId
         * @param version
         * @param formDefId
         * @param rows
         * @param primaryKeyValue
         * @return
         */
        FormRowSet storeFormData(String appId, String version, String formDefId, FormRowSet rows, String primaryKeyValue);
    
        /**
         * Store specific data row (record) for a form.
         * @param form
         * @param rows
         * @param primaryKeyValue For single-row data. If null, a UUID will be generated. For multi-row data, this value is not used.
         * @return
         */
        FormRowSet storeFormData(Form form, FormRowSet rows, String primaryKeyValue);

    Hope this helps.

    Best regards.

    1. Hi Owen,

      This looks good! The only question I have left however is is there a method to return the names and types of the form fields? In other words, I have a piece of code that works generically on all forms and I won't know in advance which fields are available in a form. I found the following method on the Form class that appears to do the trick but I just wanted to confirm:

      Form.getFormMetas()

      Will this method return a map of all the fields and their types?

      Thanks!

  2. Hi Andrew,

    Form.getFormMetas() is used for passing some internal parameters which will be render as hidden field when rendering the form.

    To get the all the Columns in a form data table, you can refer to the implementation of the getColumns() methods of FormRowDataListBinder

    Hope this helps. :)

    Best regards.

    1. Thanks Owen!

      Ok, got it. So I use the AppService API to get my form, and then I can use the code in getColumns() as an example of how to retrieve the form field names.

      Cheers!