how to inject #currentUser.*# Hash Variable inside a Bean Shell Form Binder (inside java code)

Confluence User - 16 Jan, 2016

Hello,

 

Does someone know how to pass either a Hash Variable (such as #currentUser.*#) or the user (with environment variables?) or a Workflow variable (from a TextField) as an argument (or a variable) inside Java code inside Bean Shell Form Binder?

 

Many Thanks,

 

Regards

 

Alexandre

forms

14


16 Jan, 2016
confluenceUser
confluenceUser

Create a hidden field with the value as your required hash variable.

When the form will be submitted you willbhave access to the resolved value in the bean shell and you can use it as required 

16 Jan, 2016
confluenceUser
confluenceUser

Hi there,

Are you using the Bean Shell Form Store Binder?
If yes, then you could easily use any string variable to reference the currentUser or environment Hash Variables.

Let me know if this helps!

Thanks

16 Jan, 2016
confluenceUser
confluenceUser

Thanks for the answer. So can you explain me how to get this "resolved value" inside the Java code? That's the part I definitely miss. Many Thanks,

16 Jan, 2016
confluenceUser
confluenceUser

Thanks for the answer, but how can I fill a String variable with the currentUser or environment Hash Variables? Do you have some code sample? Many Thanks,

16 Jan, 2016
confluenceUser
confluenceUser

When the form loads joget load binder will resolve the hash variable and populate the value in the hidden field. So you don't need to do anything till this point. When the form is submitted just access this hidden field like anyother form field. Just try it i have been using this trick and it works

16 Jan, 2016
confluenceUser
confluenceUser

Hello Alexandre,

I pretty sure the following would work on a Store Binder:

String s = "#currentUser.username#";

Please let me know if this helps.

 

Thanks!

16 Jan, 2016
confluenceUser
confluenceUser

Hello Ashutosh, Except if there's some special instruction before, when I use your code, a System.out.println(s) only gives me #currentUser.username# but not the value inside it. Did I miss something? Thanks, Alexandre

16 Jan, 2016
confluenceUser
confluenceUser

Thanks for your answer. So how can you get the value inside the Bean Shell Form Binder? I need this value inside the Java code. Thanks, Alexandre

16 Jan, 2016
confluenceUser
1
confluenceUser

Hi Alexandre,

That works for me though.

Please publish this sample application and submit the first form.

APP_testApp-1-20160116004507.jwa

Hope this helps!

Thanks

16 Jan, 2016
confluenceUser
confluenceUser

Thank you! Now it works.

I'm wondering why earlier it didn't...

By any chance do you know instead of using an Hash Variable I can use a Value entered in a previous TextField box?

I think there should be a way to get this value through the "Workflow Variable" but can't find how...

I still need to get the value inside the Bean Shell Form Store Binder to use it as a data for my Java code.

 

Thanks,

 

Alexandre

16 Jan, 2016
confluenceUser
confluenceUser

There are a few ways you could get the values of the textFields in your BeanShell.

  • You could use the Form Hash Variables. Something like #form.<table-name-of-the-form>.<textfield-id># should work if you're trying to get the values from the same process instance.
  • You could set the values in the Workflow Variables by binding the textfield to a Workflow Variable & fetching it's value in the binder using #variable.<workflow-variable-id># if the value you're trying to get is on some previously submitted form.
  • If you're trying to manipulate the values of the same form, you could use the following in your store binder:

    FormRow row = rows.get(0);
    row.getProperty("<textField-id>");

          Make sure that you import the required classes in this case.

  • Finally, you could always use a JDBC code to fetch values from the database whenever required.

 

Please let me know if these help.

Thanks!!

 

 

 

16 Jan, 2016
confluenceUser
confluenceUser

Hello,

 

Thanks again! That's really what I'm looking for.

As I need to manipulate the value of same form the last option is the one I need.

But where comes from your "rows" object? I think it's a kind of global variable, but how to "load" it?

 

Thanks,

 

Alexandre

16 Jan, 2016
confluenceUser
confluenceUser

Whenever a form is submitted, all the data from its fields goes into the 'rows' object which would be available in the store binders that would get executed next. For more information or to learn how the 'FormRows', 'FormRowSet' etc., I'd suggest you build the Joget Workflow in your IDE and debug the steps. It'd be highly informative and self-explanatory. Thanks!

18 Jan, 2016
confluenceUser
confluenceUser

Thank you again for your answer and the advice. We're going to do like this. Regards, Alexandre

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print