Table of Contents |
---|
Problem Statement
English |
---|
In this article, we will walkthrough the thought process of designing a solution for the following business use case:-
This is an example of what the form would look like. |
Figure 1
The only external factor that may be outside of the Joget platform's control would be the external integration with the CRM software. We will walkthrough a few scenarios on how best to design for this business use case with UI/UX kept in mind.
...
- We will start with designing the form itself. The form itself is quite simple, with just 3 fields and all of them made mandatroy.
Figure 2 - In the userview, we are making use of the Form Menu and link it to the form we have just designed.
Figure 3
Configure "Action to Perform After Form Saved" to redirect to a "HTML Page" to show form submitted message (e.g. Form submitted. Thank you!). - Do not forget to create a CRUD menu too so that we can browse through all the submissions easily using Generate CRUD.
Figure 4 - At this point in time, there's no integration yet with the external CRM.
...
- Form Validation - Joget would iterate through each and every form element and invoking the validator (if configured).
Figure 5
If all validations pass, then it will move to the next step, else, end user will be redirected back to the same form with validation errors displayed like what is shown in the screenshot below.
Figure 6 - Form Store - Since validations have passed, Joget will now proceed to the next step, form data will be passed to the store binder.
Figure 7
By default, the load/store binder is Workflow Form BinderDefault where it will load and store form data into the table name declared in the form properties. In this case, the table name is "demo_request". - Since we are using Workflow Form BinderDefault, this would also mean that we are saving the form data locally in Joget's database.
...
The easiest, no-code approach is to make use of JSON API Tool plugin itself. The JSON Tool itself is a Process Tool & Post Form Submission Processing Plugin. This means that we can invoke it from within a process flow or from the submission of the form.
...
We can also write Bean Shell code. Here's a quick sample code to make HTTP get call.
Code Block language java title Bean Shell code to make restful API calls sample linenumbers true import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import java.io.IOException; import org.joget.commons.util.LogUtil; try{ String jsonUrl = "http://localhost:8080/jw/web/json/workflow/assignment/list/count?packageId=crm"; //sample url String name = "header1"; String value = "value1"; CloseableHttpClient client = null; CloseableHttpClient client = HttpClients.createDefault(); HttpRequestBase request = null; request = new HttpGet(jsonUrl); request.setHeader(name, value); HttpResponse response = client.execute(request); } catch (Exception ex) { LogUtil.error(getClass().getName(), ex, ""); } finally { try { if (request != null) { request.releaseConnection(); } if (client != null) { client.close(); } } catch (IOException ex) { LogUtil.error(getClass().getName(), ex, ""); } }
We can execute this piece of code from various plugin types giving us the flexibility on where/when we want to invoke it. The only disadvantage compared to the former is that we need to maintain the custom coding ourselves instead of configuring through a plugin. These are the plugin types relevant to our solution to call the code from:-
Method 3 - JSON Tool from Bean Shell Code
...
By using Post Form Submission Processing in Form, and "Method 1 JSON Call" earlier, this is the easiest and quickest method. This allows us to invoke any Process Tool & Post Form Submission Processing Plugin. JSON API Tool is one such candidate.
Figure 9
- Upon form submission, form fields will be validated, with its form data stored, then, the "Post Form Submission Processing" will be triggered.
- Response time of form submission will now include complete execution of the JSON Tool.
- Imagine that the external JSON API takes longer than expected to respond, the end user will be kept waiting.
Depending on the feature of the API call, we would assume that it would return a response to indicate successful execution. For example:-
Code Block language js title Sample JSON Call Response { "success" : "true" }
- By using this integration point, there's no way to redirect the user to other place/menu when error occurs.
...
To avoid the waiting time for JSON Tool to finish executing, we can place it under Multi Tools instead.
Figure 10
Set the "Run Mode" such that it would execute the process tool (JSON Tool) in a new thread.
...
We can try to throw an exception instead in the Bean Shell code that we are writing.
Figure 12
This approach suffers from the following issues:-
...
Taking cues from method 2 earlier, we will put the new plugin in Multi Tools and set the Run Mode to "Run tools sequentially in a new single thread". This is so that customer does not need to wait for JSON call to complete.
Figure 13
The following is a new section to configure to capture the JSON call's response status.
We created a new form to capture the JSON call log.
Figure 14
In this screenshot below, we are able to inspect each of the form submission made (left) and the result of the API call (right).
...
For example, we can make use of the Form Update Process Tool Datalist Action and map to the JSON Tool.
Figure 18
Once it is tested working, we can consider automating it and set up a scheduler job - iterate through the same list and execute JSON Tool using Iterator Process Tool.
...