How to get a business variable to feed a REST connector request

1
0
-1

Hello,
I try to do a Hello World process example.
The Contract of the process is a Business object (an instance of a BOM class in my case). This a class is named "com.company.Client". One string attribute 'name'. So I expect to do Hello World with the name variable client.name
The web form is generated properly using this Business class.
My problem is how to get the name attribute of the process Client instance to instantiate a REST Connector URL.
I need to do a REST GET on a HelloWorld service (which works perfect).
After reading the doc and looking at videos, I infer that the URL shall be something like : http://localhost:8088/hello/{{com.company.client.name}}
But the instance value is not got and the connector fails.
Can somebody explain how to get variables in the connector setup ?
Thanks a lot
GB

1 answer

1
0
-1

Your code was almost right, just a few mistakes:

  • syntax with {{ is a way to specify data binding in HTML when using AngularJS. This is used in Bonita forms and pages created with Bonita UI Designer but not in connector configuration.
  • com.company.Client is the data type definition (i.e. the Java class) and client is the business variable (i.e. the Java object). As you want to use the value of an attribute of the business variable object you need to use client.name without com.company (that is the Java class package name).

So in your connector configuration, for the URL, click on the pencil icon and choose the Groovy editor, and define the following expression (including double quotes): "http://localhost:8088/hello/${client.name}".toString()

Double quote create a Groovy GString that allow string interpolation but as the connector expect a String and not a GString we call the toString mtehod to do the conversion.

Finally note that you can also do REST calls directly from Bonita forms/pages. You can use a form variable of type "external API" that will trigger a GET operation or use a button widget that can be used to do POST, PUT, GET and DELETE.

Comments

Submitted by GeekBot on Thu, 08/15/2019 - 08:11

Hello Antoine,
Thanks very much for this detailed explanation which makes things clear.

In the mean time, I found another solution which seems to work.
a/ In the connector setup wizard, I set "url()" in the GET URL* panel
b/ I edit the url as a script, and place this line of code :
return "http://localhost:8088/hello/" + newClient.name
So, It concatenates the two strings and the job is done.

Best regards
GB

Submitted by antoine.mottier on Wed, 08/21/2019 - 10:25

Good to know that your solved your problem. Your solution is quite the same as mine, only difference is I tried to use a little bit Groovy features (I'm still learning this language and want to practice) such as GString interpolation and optional return statement.

If my answer solve your problem can I ask you to check the tick to mark it as best answer? This way we know that the issue is solved. Also note that you should usually rather use comments except when actually providing an answer to a question. Thanks.

Notifications