1 answer
- 10-1
Hi, I think it is not possible for the beanshell to be passed on the client-side(Frontend UI) of the application.
BeanShell is a server-side scripting language used in Joget. It runs on the server, not on the client side. Therefore, you cannot directly pass JavaScript variables to BeanShell since JavaScript runs on the client side (in the browser), and BeanShell runs on the server.
However, you can pass data from JavaScript to BeanShell indirectly by using form fields as intermediaries
Add Hidden Field to Your Form:
html
<input type="hidden" id="hiddenField" name="hiddenField" />
Set Hidden Field Value Using JavaScript:
javascript
<script> function setHiddenFieldValue() { var jsVariable = "someValue"; // Your JavaScript variable document.getElementById("hiddenField").value = jsVariable; } // Call this function when you need to set the value setHiddenFieldValue(); </script>
Access Hidden Field Value in BeanShell:
java
import org.joget.workflow.model.service.WorkflowManager; import org.joget.apps.app.service.AppUtil; // Get the hidden field value String hiddenValue = request.getParameter("hiddenField"); // Set the value to a process variable WorkflowManager wm = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager"); wm.activityVariable(workflowAssignment.getActivityId(), "procOutput", hiddenValue);
By following these steps, you can check whether you can pass data from JavaScript (client-side) to BeanShell(server-side) using a hidden form field in Joget.
You can try on your end. Let me know if it works.- NAS
Hi,
Thanks for the clarification. I have tried implementing your suggestions, unfortunately, it is not working as expected. To be precise, after few testing, the steps to get the hidden field value leads to java.lang.NullPointerException: Null Pointer in Method Invocation error in the logs. Any thoughts on where I might do wrong or miss something out to make this successful?
In the meantime, I have fully converted all the logics from BeanShell to Javascript and its working fine (so glad for this). Still, I was kinda hoping on how I can utilize BeanShell so that I can have a cleaner code base.
Thank you!
Add your comment...
Hi All,
I am trying to pass JavaScript variable to a Bean Shell script declared in App Variable. For instance, as below:
However, in the console log, it keeps on displaying the call to the Bean Shell script as a string, as follows:

If I directly use the value Homepage and call the Bean Shell script, as below, it is working and accessing the Bean Shell script as expected.
Is there any ways to pass Javascript variables to the Bean Shell?
Thanks!