Font Size:
Ask Joget AI

How to use Beanshell to Import an App

Introduction

This guide shows you how to import an app using a BeanShell script. By automating the app import process, you can streamline deployments and work more efficiently across different environments. However, there are a few constraints that you must observe to be able to do so successfully.

How does it work?

  1. In Form Builder, add a File Upload and Text Field form element to a form.


  2. Click Generate App, select Generate CRUD, and then click Generate to proceed.


  3. Open the List Builder and drag the BeanShell element into the table to add it as an action. Copy and paste the script below into the Script section.


    import java.io.File;
    import java.nio.file.Files;
    import java.net.URL;
    import org.apache.commons.io.FileUtils;
    import org.joget.apps.app.service.AppUtil;
    import org.joget.apps.util.AppLicenseUtil;
    
    // prep the filepath
    String rowid = Arrays.toString(rowKeys);
    String filename = "#binder.t6235.f1.field1["+rowKeys[0]+"]#"; //filename is in fileupload field "field1" of form f1
    filename = AppUtil.processHashVariable(filename, null, null, null, null);
    String filepath = "#request.baseURL#/web/client/app/#appDef.appId#/#appDef.version#/form/download/f1/"+rowKeys[0]+"/"+filename;
    //filepath = "#request.baseURL#/web/client/app/t6235/1/form/download/f1/5384541b-1baf-4419-95a8-9fbf0222656e/APP_FileAddImageSampleApp-1-20231120175830.jwa.";
    
    System.out.println(filepath);
    
    // make the file & stream
    URL url = new URL(filepath);
    File file = new File("wflow/app_tempfile/test.jwa");
    FileUtils.copyURLToFile(url, file);
    System.out.println("copied");
    byte[] fileContent = Files.readAllBytes(file.toPath());
    
    // fire
    AppLicenseUtil.importApp(fileContent);
    
  4. Save and launch the app. 

Expected Outcome

Once you have implemented the above steps, here is what it would look like in runtime:
 

Download sample app

Download the demo app for Import an App using Beanshell:
Created by Nurkhairini Fitrah Last modified by Nur Baizura Badrul Sham on Aug 04, 2026