Wednesday, November 13, 2019

AJAX Service Call from Coach in BAW

ABSTRACT:
Making an Ajax Service Call from Coach to get result in BAW

DESCRIPTION:
If you wish to get the result of a service call in the UI dynamically based on the inputs in the coach, then how will you create a service to be accessible in the coach? Lets assume there is a calculate service that takes in a string (as 15+56) as input and returns the result of the operation. I want this input values 15 and 56 to be entered in the UI with an operation entered like + or - or * or /. 
How will you call this service from your coach?

SOLUTION WITH EXAMPLE:
1. I have created a Client Side Human Service HS_Order with a Coach "Order"


 2. The Coach has a few components like input text i.e "inp1", "inp2", "operation" and "result"; button i.e "calculate" and a service call i.e "Calculate Service call" and 4 data components for each of the input Texts for calculations.




3. Looking at the properties of the calculateService we see the called service is "calculateService"
4. "CalculateService" was a service created by Services -> + -> Service Flow ->Enter Service name -> Finish


 5. Overview of the CalculateService:


  • Diagram of the CalculateService: The service has 1 script activity.
  • In the script of this activity, below is the javascript code that I have:

log.info("init of calculateGss service...");
var a = tw.local.data.toString();
var str = a.split("-");
log.info("num1:"+str[0]);
if(a){
if(a.indexOf ("+", 0) >= 0){
var str = a.split("+");
var num1 = Number(str[0]);
var num2 = Number(str[1]);
tw.local.results = parseInt(num1)+parseInt(num2);      
}else if(a.indexOf("-", 0) >= 0){
  var str = a.split("-");
  var num1 = Number(str[0]);
  var num2 = Number(str[1]);
  tw.local.results = parseInt(num1)-parseInt(num2);      
}else if(a.indexOf("*", 0) >= 0){
  var str = a.split("*");
  var num1 = Number(str[0]);
  var num2 = Number(str[1]);
tw.local.results = parseInt(num1)*parseInt(num2);           
}else if(a.indexOf("/", 0) >= 0){
  var str = a.split("/");
  var num1 = Number(str[0]);
  var num2 = Number(str[1]);
tw.local.results = parseInt(num1)/parseInt(num2);      
}else{
var num1 = 0;
var num2 = 0;
tw.local.results = 0;
}
}



  • Variables of the CalculateService:




Now, my CalculateService is ready.


6. Next, in the "Order" coach, where I have the calculate button, I will add the below code in the On-Click event property:  
            var input = ${Data1}.getData()+${Data3}.getData()+${Data2}.getData();
       console.log("input is:"+input);
       ${Service_Call2}.execute(input);
7. In the calculateService -> On Result, I will have below code:
console.log("calculate result:"+me.getResult());
     ${Data4}.setData(me.getResult());
8. In CalculateService -> On Error , I will have below code:
console.log("calculate error..");
9. Now, when I run the Client Side Human Service "HS_Order", I should be able to get the result on entering the numbers and operation:
10. However, I find that the result is still appearing as "0".

11. On checking the logs, I see that the On error block got executed. 
 12. The problem was in the Service Definition i.e. Overview of "CalculateService".
13.Here, I have considered the alternative to resolve this issue. Under "Ajax Section", select "Allow Calls from all users" instead of "Allow calls from trusted users" (to use this see at the bottom of this post).

14. Now, run the "HS_Order" and enter the inputs and operation. You will be able to see the result in the result text box. 


This way, I was able to make use of the service call to make an AJAX call in the UI.

ALLOW CALLS FROM TRUSTED USERS:
1.  First, I create a team with name "CalculateUser" with one user "swethaj"
 2. In CSHR "HS_Order" -> Overview -> Usage, I select "Startable Service" in Use as and in Expose as Start I select the team "CalculateUser".
3. This means only the users defined under the team "CalculateService" will have access to the services in the CSHR.  
 4. Now, I login the processCenter with another user say "Admin" that has access to my process app.
5. On running the CSHR "HS_Order", entering the values and clicking on "Calculate" button, the result value doesn't change and the console shows "ConnectionError" as observed.

6. When logged in with user "swethaj", I will get the calculated result in the result field. 

Thus, in this way Service Flow can be used for AJAX calls for trusted users only.


Sunday, November 10, 2019

Expose & Display Variables in the BAW Process Portal's Worklist

ABSTRACT:
Expose and Display Variables in the BAW Process Portal's Worklist

DESCRIPTION:
If you wish to display the details of a record in the tasks records of the worklist of a user, then how will you do that?

SOLUTION WITH EXAMPLE:
1. Consider I have a Process App with name "HR Portal Application" with a process "HR Enrollment Process".
2. I want the variable "instanceId" value to be shown in the worklist of my process portal.
3. For the variable "instanceId" in variables tab of the process, the "Visible in Process Portal" checkbox should be checked and an alias name say "instanceNumber" should be given.



 4. Now, in Process Portal, under "dashboard", click on "Work" and in the centre of the page, where you can see "Work", click the "actions" option. Here I will find an option "Edit Columns".



5. The Available columns popup will open up, where I will search for the variable I have marked as exposed i.e. "instance Number" 


6. I will check the checkbox for this variable and click 'ok' button.



7. Now, when the process "HR Enrollment Process" is run, then in the worklist item, the instance Number column with its value will be visible. 



8. Note that for the instances created before exposing this variable and adding this column, the instance number value will not get displayed. 



9. Also note that if the alias of the variable is changed for a newer snapshot and deployed; and the previous snapshot data is not migrated. If there are instances of the previous snapshot referring to the older alias, then the value for those instances for this variable will show as blank as the alias it is pointing at is different and the system couldn't find any value for the new alias for that record.

Friday, November 8, 2019

Environment variables in BAW Client Side Human service

Abstract:
Using Environment variables defined at Process App/ Toolkit level in the Client Side Human Service in IBM BAW

Problem:
The environment variable values not appearing in Client Side Human Service.

Description:
1. Lets say you have an environment variable created in you process app which you want available across all your services in the app.
2. For instance your Environment variable name is 'applicationId'; if you have any service created in the process app, then using tw.env.applicationId will give you the value present in this variable as result.
3. However, if you have a Client Side Human Service and you want to use this environment variable within this, then you will observe that the value returned will be null.

Solution with Example:

1. I have an application "HRSJ BAW Application" with an environment variable "applicationId" with value "101" and a client side human service "HR Portal".

2. "HR Portal" has an output variable "appId" created

3. "HR Portal" also has 2 activities in the diagram "Init" (script activity) and "Coach" (Coach activity).

4. In "init" script, the value of the environment variable 'ApplicationId' is being assigned to output variable 'appId' with console logs printed to see the value for the ids.

5. In "coach", there is a Text field which has binding as 'appId'.

6. On executing the HR Portal human service, it will be observed that there is no value populated in the text field.

7. This means the environmental variable has not been assigned to appId.
8. On checking the console, I find that the environmental variable "applicationId" also is undefined.
9. On analysis, I find that i will have to add the environmental variable in the variables section of my human service "HR Portal".


10. Now on running the application, the value will be populated in both the UI as well as the console.