Yes indeed ,it's on Container. I do not need to pass a ltpaToken2 in headers but "Authorization : bearer". Like this it's working:
Original Message:
Sent: Thu October 20, 2022 03:57 PM
From: Michael Kirchner
Subject: Make case comment mandatory and display the username
Hi John,
I'm not 100% sure but 401 means that your access is not authorized.
As you mention "OpenID Connect client failed the request." in the error message, I assume that your implementation is based on containers, is that correct?
It is possible that the helper method I used to obtain the SSO token
var ssoToken = Packages.com.ibm.websphere.security.web.WebSecurityHelper.getSSOCookieFromSSOToken();
log.info(ssoToken.getValue())
request.httpHeaders = {"Content-Type": "application/json",
"Accept": "*/*", "Cookie": "LtpaToken2="+ssoToken.getValue()};
only works on tWAS but not on container based deployments which use WAS Liberty. To be honest, I did not test it on containers (yet).
Have you checked if the method returns a valid SSO token? The statement log.info(ssoToken.getValue()) should log the token value to the log. You can also directly check it in your JS code. It may be helpful to test the API call via e.g. POSTMAN using the SSOToken as cookie. This way you can validate whether you have a valid token to call the API.
Does that help?
Best regards,
Michael
------------------------------
Michael Kirchner
Leading Technical Specialist - Digital Business Automation
IBM Technology
Germany
Original Message:
Sent: Thu October 20, 2022 02:53 AM
From: John Amexio
Subject: Make case comment mandatory and display the username
Hello Michael,
i try to reproduce the procedure you define to call the addComment operation from a CSHS which is the case details page in my case. (I developped a BAW application including Case Management Features).
I used the same code as you, but I got this error message from the response content : "OpenID Connect client failed the request... 401" -> see screenShot.
Do you have any idea what could be wrong ?
Thank you, have a nice day,
John
------------------------------
John Amexio
Original Message:
Sent: Thu September 01, 2022 12:09 PM
From: Michael Kirchner
Subject: Make case comment mandatory and display the username
Hi Antoine,
I assume that you are in general familiar with the client side human services (CSHS) and also with the ways how a BPM process can call REST services?
In general, there are probably at least three options, how you can call the Case REST service to create a comment in a way that the authentication of the current user is leveraged.
- By using an XMLHttpRequest via JavaScript defined in a Coach/CoachView
- By using the "Service Call" Coach View on the Coach page
- By calling the REST service via JavaScript on the Coach page and re-using the authentication of the user
I've tested option "c" and it worked for me. Here's a brief summary what I did:
- Define a REST Service for the Case REST resource which is used to create a comment. For that purpose I created a small swagger YAML and imported in Web PD to define the service and the REST server. Go to the REST server definition and set hostname and port according to your environment. Leave the authentication set to "None". For the REST call, I used the commentText, the caseID and the Case Target ObjectStore as parameters.
- Define a Service Flow to call the REST Service you defined in step 1 via JavaScript. Pass the LTPA token of the current user so that the call is executed as the authenticated user. The service flow also takes the parameters which the REST call requires.
- Call the service flow from the Coach that is used by the Case Activity where a comment shall be provided. I defined private variables for the REST parameters and used a text CV on the coach so that the user can add a comment. You can use the regular validation mechanisms to check if the user provided a comment and provide an error message if the comment is missing.
Some more useful details:
- I used
tw.local.caseID = tw.system.processInstance.parentCase.caseId
tw.local.caseID = tw.local.caseID.substr(1,tw.local.caseID.length -2);
to retrieve the caseID for the current case from the case activities coach and trimmed the leading and trailing curly braces (as the REST call only uses the caseID w/o curly braces). - I used
tw.local.body.CommentType = "Case";
tw.local.body.CommentText = tw.local.commentText;
var request = new BPMRESTRequest();
request.externalServiceName = "AddCaseCommentCookieAuth";
request.operationName="addComment";
request.httpMethod = "POST";
request.endpointAddress = "https://ibmbaw:9443/CaseManager/CASEREST/v1";
request.path = "/case/"+tw.local.caseId+"/comments";
var ssoToken = Packages.com.ibm.websphere.security.web.WebSecurityHelper.getSSOCookieFromSSOToken();
log.info(ssoToken.getValue())
request.httpHeaders = {"Content-Type": "application/json",
"Accept": "*/*", "Cookie": "LtpaToken2="+ssoToken.getValue()};
request.parameters = {"TargetObjectStore": tw.local.TargetObjectStore,
"caseId" : tw.local.caseId,
"body": tw.local.body};
request.requestTimeout = 2000;
request.responseTimeout = 7200;
log.info("------------------------------------------------------------------");
log.info("Request - URL " + request.endpointAddress+request.path);
var response = tw.system.invokeREST(request);
log.info("------------------------------------------------------------------");
log.info("Response - httpStatusCode: " + response.httpStatusCode);
log.info("Response - httpStatusMessage: " + response.httpStatusMessage);
log.info("Response - httpHeaders: " + response.httpHeaders);
log.info("Response - content: " + response.content);
log.info("------------------------------------------------------------------");
// Evaluate the response and process as necessary
var httpStatusCode = response.httpStatusCode;
var httpStatusMessage = response.httpStatusMessage;
var httpHeaders = response.httpHeaders;
var content = response.content;
to retrieve the LTPA token and to pass it into the header of the REST request.
I've attached the YAML to define the REST Service to this post.
Let me know whether you were able to implement your requirement.
Best regards,
Michael
------------------------------
Michael Kirchner
Leading Technical Specialist - Digital Business Automation
IBM Technology
Germany
Original Message:
Sent: Tue August 30, 2022 08:50 AM
From: Antoine Inguenault
Subject: Make case comment mandatory and display the username
Hi Michael,
Roussaya and I worked on the same project 2 weeks ago. She was in internship, but she didn't work on this subject anymore.
Yesterday, I tried to implement the requirement, but I have some problems to do it. I understand your logic, but I don't know how to call the Case REST API from a coach and where the JSON is supposed to be localized.
It would help me so much if you could give me further details.
Thank you for your help,
Best regards,
Antoine
------------------------------
Antoine Inguenault
Original Message:
Sent: Mon August 29, 2022 12:25 PM
From: Michael Kirchner
Subject: Make case comment mandatory and display the username
Hi Roussaya,
have you been succesful in implementing your requirement in the case solution?
I ran a few tests and can confirm that you can successfully call the Case REST API from a coach to add a comment to a case using the logged on user. Let me know if you need further details.
Best regards,
Michael
------------------------------
Michael Kirchner
Leading Technical Specialist - Digital Business Automation
IBM Technology
Germany
Original Message:
Sent: Fri August 19, 2022 11:13 AM
From: Roussaya SORDA
Subject: Make case comment mandatory and display the username
Hi Michael,
I will try your solution. I hope this will work.
Thank you for your help !
------------------------------
Roussaya SORDA
Original Message:
Sent: Thu August 18, 2022 06:17 AM
From: Michael Kirchner
Subject: Make case comment mandatory and display the username
Hi Roussaya,
I assume for your second example you are capturing the comment in a mandatory field in your coach and you use a script task to execute tw.system.currentProcessInstance.parentCase.addCommentToCase after completing your user based case activity step, correct?
In that case the JS API is not called in the context of the user who worked on he user task but by a system user and thus you see this user (in your example P8Admin) as the creator of the comment.
The "Case Comment" coach view uses the Case REST API comment resource
https://www.ibm.com/docs/en/baw/22.x?topic=resource-post-method-case-comments
to add user comments to cases.
You need the caseID (which you can obtain in the coach) to construct the URL and you need to provide the Target OS (which you can store in a variable or an environment variable) as parameter when calling the URL.
Besides you have to pass along a JSON in the request body which has the following information
{
"CommentType" : "Case",
"CommentContext" : 102,
"CommentText" : "Your comment text.."
}
You could try to call this REST service in context of your coach in order to add your comment, however I haven't tried that before.
As you already copied and modified the Case Comment coach view, another option might be to change the event in such a way that the "Add Comment" section automatically opens when the coach view is loaded (as opposed to open it by clicking on the link). But users would still have to click on the "Post" button or could cancel the dialog but that would be something you might be able to avoid by tweaking the coach view.
Best regards,
Michael
------------------------------
Michael Kirchner
Leading Technical Specialist - Digital Business Automation
IBM Technology
Germany
Original Message:
Sent: Thu August 18, 2022 03:15 AM
From: Roussaya SORDA
Subject: Make case comment mandatory and display the username
Hi Michael,
The comment must be mandatory when the user working on a case activity. Unfortunately, I have dificulties to make the comment mandatory on the coach in my workflow.
------------------------------
Roussaya SORDA
Original Message:
Sent: Wed August 17, 2022 11:42 AM
From: Michael Kirchner
Subject: Make case comment mandatory and display the username
Hi Roussaya,
I don't think that there is a way to make case comments mandatory in all places, so can you please provide a bit more information in which context / use case you want to add a mandatory comment?
Is it when working on a case activity or do you want make the comment mandatory when a user opened the case details view?
Best regards,
Michael
------------------------------
Michael Kirchner
Leading Technical Specialist - Digital Business Automation
IBM Technology
Germany
Original Message:
Sent: Fri August 12, 2022 11:46 AM
From: Roussaya SORDA
Subject: Make case comment mandatory and display the username
Hello Everyone,
I would like some help to make comments mandatory for coaches in BAW 22.0.1.
I have tried setting up the case comment in two ways :
- First, I copy the view case comment provided by the case toolkit to be able to modify the view.
Then, I used this view in my coach by configuring the visibility (required).
Unfortunately, the case comment is not mandatory for the user in the coach.
2. For the second way, I configure a text fields and then use the following method : tw.system.currentProcessInstance.parentCase.addCommentToCase(tw.local.coment);
But when a user adds a comment in the coach and I check the comments case, the name user is always the administrator (P8admin).
I don't know how to associate the added comment and the user name.
To sum up :
- If I use the view case comment, I don't know how to make the field mandatory but I have the username.
- If I use the method addCommentToCase(), the field comment is mandatory but I don't have the username.
Does anyone know how I can have a comment mandatory with the username displaying correctly ?
Thank you for your help !
------------------------------
Roussaya SORDA
------------------------------