01-19-2023 11:21 AM
I am trying to fetch Rejection Comments in an email template by using the below piece of code:
Request rejection comment -${def r=allRejectors.collect{it.username}.join(',').toString();r=r.replaceAll("[, ;]","");def ec=accessItems.collect{it.comments}.join(',').toString();def rc=ec.substring(ec.lastIndexOf(r+")] ")+(r+")] ").length());return rc;}
The email is not being parsed and I am getting the below error in logs:
{"log":"SimpleTemplateScript2576.groovy: 2: unexpected char: '\\' @ line 2, column 106.\n","stream":"stdout","time":"2023-01-19T19:01:34.270081009Z"}
I am not able to figure out what the issue is.
Any help would be appreciated.
Thanks.
Solved! Go to Solution.
01-19-2023 11:38 AM
Can you paste the content of email template you have used?
Because as per logs it is complaining about \\ but don't see such character your expression.
Also did you try to break down the expression and see where it causing the issue?
Also what is the format you are trying to get as output
01-19-2023 10:33 PM - edited 01-19-2023 11:07 PM
Below is the email template:
<img alt="" src=""><br><br><div>Hi ${requestor.firstname} ${requestor.lastname},<br><br>Your request for ${if(requestor?.username == user?.username) {return "yourself";} else {return user.firstname+' '+user.lastname+'-'+user?.username;}} for Planning Cloud with Request ID - ${requestid} has been rejected.<br><br>Rejected By -${allRejectors.collect{it.username}.join(',')}<br>Request rejection comment -${def r=allRejectors.collect{it.username}.join(',').toString();r=r.replaceAll("[, ;]","");def ec=accessItems.collect{it.comments}.join(',').toString();def rc=ec.substring(ec.lastIndexOf(r+")] ")+(r+")] ").length());return rc;}<br><br>Regards<br> <br><br></div><img alt="" src="">
Let's say the comments are:
[01/19/23 15:39:21 UTC -Ram Singh (ABCD)] sqdwewdew
[Jan 19, 2023 15:40:48 UTC - Shyam Singh(CDER)] reject1
From the above example, I just want to fetch the rejection comment which is: "reject1".
So, what I am trying to do is ..since the rejector's username+")] " will be present only once in the entire comment, I am fetching the last index 0f "CDER)] ". Because, after that we will just have the rejection comment by this user(rejector).
01-20-2023 10:14 AM
The below code worked for me. But it works only if the workflow is a serial workflow i.e it ends whenever any rejector rejects a request.
Request Rejection Comment - ${accessItems.collect{it.comments}.join(',').toString().substring(accessItems.collect{it.comments}.join(',').toString().lastIndexOf(allRejectors.collect{it.username}.join(',').toString().trim()+')] ')+(allRejectors.collect{it.username}.join(',').toString().trim()+')] ').length())}
01-20-2023 11:32 AM
So you requirement is fulfilled ?
01-20-2023 12:05 PM
For now..yes