BPM, Workflow, and Case

 View Only
Expand all | Collapse all

Make case comment mandatory and display the username

  • 1.  Make case comment mandatory and display the username

    Posted Fri August 12, 2022 11:47 AM

    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 :

    1. 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
    ------------------------------


  • 2.  RE: Make case comment mandatory and display the username

    Posted Wed August 17, 2022 11:42 AM
    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
    ------------------------------



  • 3.  RE: Make case comment mandatory and display the username

    Posted Thu August 18, 2022 03:16 AM
    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
    ------------------------------



  • 4.  RE: Make case comment mandatory and display the username

    Posted Thu August 18, 2022 06:17 AM

    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
    ------------------------------



  • 5.  RE: Make case comment mandatory and display the username

    Posted Fri August 19, 2022 11:13 AM
    Hi Michael,

    I will try your solution. I hope this will work.

    Thank you for your help !

    ------------------------------
    Roussaya SORDA
    ------------------------------



  • 6.  RE: Make case comment mandatory and display the username

    Posted Mon August 29, 2022 12:26 PM
    Edited by Michael Kirchner Mon August 29, 2022 02:52 PM
    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
    ------------------------------



  • 7.  RE: Make case comment mandatory and display the username

    Posted Tue August 30, 2022 09:30 AM
    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
    ------------------------------



  • 8.  RE: Make case comment mandatory and display the username

    Posted Thu September 01, 2022 12:09 PM
      |   view attached
    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. 
    1. By using an XMLHttpRequest via JavaScript defined in a Coach/CoachView
    2. By using the "Service Call" Coach View on the Coach page
    3. 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:
    1. 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.
    2. 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.
    3. 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
    ------------------------------

    Attachment(s)

    yaml
    addCommentCaseREST.yaml   2 KB 1 version


  • 9.  RE: Make case comment mandatory and display the username

    Posted Fri September 09, 2022 08:21 AM
    Hello Michael, 

    Thank you for your answer. 
    I was on another project this week, so I didn't have the time to try your implementation. I had time to try it today, and it works well ! 
    For the script in my service flow, the only thing I add compare to yours was this line at the beginning :
    for the body  --> tw.local.body = new tw.object.Body();

    Thanks again for your help, 

    best regards, 
    Antoine

    ------------------------------
    Antoine Inguenault
    ------------------------------



  • 10.  RE: Make case comment mandatory and display the username

    Posted Wed September 14, 2022 05:55 AM
    Hi Antoine,

    many thanks for your feedback, glad to hear that it worked for you!

    Best regards,
    Michael

    ------------------------------
    Michael Kirchner
    Leading Technical Specialist - Digital Business Automation
    IBM Technology
    Germany
    ------------------------------



  • 11.  RE: Make case comment mandatory and display the username

    Posted Tue October 11, 2022 10:30 AM
    Hello Michael,

    I have tried to implement your suggested code with version 21.0.3. However CommentContext seems to be incoreect, can you suggest what value to use in order to get request called? 
    E com.ibm.casemgmt.intgimpl.messages.CaseMgmtLogger error FNRPA0080E The CommentContext request parameter has an invalid value of 102.
                                     com.ibm.casemgmt.api.exception.CaseMgmtException: FNRPA0080E The CommentContext request parameter has an invalid value of 102.


    ------------------------------
    Donata Mielaikaite
    ------------------------------



  • 12.  RE: Make case comment mandatory and display the username

    Posted Tue October 18, 2022 05:05 AM
    Hi Donata,

    I'm not sure why the call fails for you, but I do not think that it is related to the version (21.0.3) you are using.
    According to the documentation (https://www.ibm.com/docs/en/baw/20.x?topic=resource-post-method-case-comments), the value is determined by the CmAcmActionChoiceList. Here 102 stands for the context of the case:

    Are you using an integer data type?

    Best regards,
    Michael

    ------------------------------
    Michael Kirchner
    Leading Technical Specialist - Digital Business Automation
    IBM Technology
    Germany
    ------------------------------



  • 13.  RE: Make case comment mandatory and display the username

    Posted Tue October 18, 2022 06:42 AM
    Hello Michael,

    Mine CmAcmActionChoiceList config is the same as yours:

    body as you suggestedm:
    body = {
    "CommentType" : "Case",
    "CommentText" : "Your comment text..",
    "CommentContext": 102
    };

    However, done some digging and seems like for CommentContext we need to create private variable with type Integer and only then pass to request body, otherwise if we are passing body as above it fails.

    Thanks for the help :) finally managed to add comment with my user id :)

    ------------------------------
    Donata Mielaikaite
    ------------------------------



  • 14.  RE: Make case comment mandatory and display the username

    Posted Thu October 20, 2022 09:33 AM

    Hello Michael,

    I try to reproduce the procedure you define above in a CSHS which is the case details page in my case. (I developped a BAW application including case management features). i'm a using CP4BA 21.0.3. 

    I got this message from the response content : "OpenID Connect client failed the request... 401". (I send SC)



    Do you have any idea why i've got this error message ?

    The code I used is pretty similar to yours:

    "

    tw.local.body = new tw.object.CommentBody();

    tw.local.body.CommentType = "Case";
    tw.local.body.CommentText = tw.local.commentText;
    var request = new BPMRESTRequest();
    request.externalServiceName = "AddCaseComment";
    request.operationName="addComment";
    request.httpMethod = "POST";
    //request.endpointAddress = "https://icp4adeploy-workflow-authoring-baw-service.hive-etat-dev.svc:9443/bawaut/CaseManager/CASEREST/v1";
    request.path = "/case/"+tw.local.caseFolderID+"/comments";

    var ssoToken = Packages.com.ibm.websphere.security.web.WebSecurityHelper.getSSOCookieFromSSOToken();
    log.info(ssoToken.getValue());
    tw.local.token = ssoToken.getValue();

    request.httpHeaders = {"Content-Type": "application/json",
    "Accept": "*/*", "Cookie": "LtpaToken2="+ssoToken.getValue()};

    request.parameters = {"TargetObjectStore": tw.local.targetObjectStore,
    "caseId" : tw.local.caseFolderID,
    "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
    tw.local.httpStatusCode = response.httpStatusCode;
    tw.local.httpStatusMessage = response.httpStatusMessage;
    var httpHeaders = response.httpHeaders;
    tw.local.content = response.content;

    "

    Many thanks,

    John



    ------------------------------
    John Amexio
    ------------------------------



  • 15.  RE: Make case comment mandatory and display the username

    Posted Thu October 20, 2022 09:33 AM

    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
    ------------------------------



  • 16.  RE: Make case comment mandatory and display the username

    Posted Thu October 20, 2022 03:57 PM
    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
    ------------------------------



  • 17.  RE: Make case comment mandatory and display the username

    Posted Fri October 21, 2022 03:32 AM

    Hello Michael,

    Yes indeed ,it's on Container. I do not need to pass a ltpaToken2 in headers but "Authorization : bearer". Like this it's working:

    "request.httpHeaders = {"Content-Type": "application/json",
    "Accept": "*/*"};

    tw.local.token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Im13ZDlGb3NiX0lNSjhWcUlKTEZFVTVESVVuRUpHOU9SNi1RZjZYeGhNUUUifQ.eyJ1c2VybmFtZSI6Imp5ajcxNSIsInN1YiI6Imp5ajcxNSIsImlzcyI6IktOT1hTU....... ";
    request.httpHeaders["Authorization"] = "Bearer "+ tw.local.token; "

    The only thing I still need to do, it's to find a way to get this bearer token from my CSHS. But I created a PMR for this to ask to IBM.

    Thank for your quick reply,

    Have a good day



    ------------------------------
    John Amexio
    ------------------------------