Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to search a string in comments.

sai siva November 12, 2021

I have implemented automatic commenting on tickets after they are open more than 1 hour.

  • I need to check if the comments are not already existing to make sure there are no duplicates.
  • I need to check a string value in comments of the ticket so that duplicate comments can be avoided.

1 answer

0 votes
Tuncay Senturk
Community Champion
November 17, 2021

Hi @sai siva 

You need to be more clear. How did you implement automatic commenting? If you share some code snippets, we can help you.

However, as of my understanding, you need to use CommentManager.getComments(issue) to get all comments and check whether the comment was already made.

sai siva November 17, 2021
if( (Durval >= 3) && (esTotalDurVal < 4)) {  
issueInputParameters.setComment("Dear Manager the ticket is open more than 3 hours please respond. " +"\n"+ "\n"+
"Thanks and best regards" )
}
else if ( (Durval >= 4) && (esTotalDurVal < 5) ) {

issueInputParameters.setComment (" Dear Manager the ticket is open more than 4 hours please respond. " +"\n"+ "\n"+

}
else if ( (Durval >= 5 ) && (esTotalDurVal < 6)) {

issueInputParameters.setComment("Dear Manager the ticket is open more than 5 hours please respond. " +"\n"+ "\n"+
"Thanks and best regards" )
}
else {
}

Hi This is my automatic comments script.

 

  • the script runs for every 30 min.
  • can i search for a string for ex: "ticket is open more than 3 hours" in the comments so there wont be duplicate comments ?

     
Tuncay Senturk
Community Champion
November 18, 2021

Hi @sai siva 

I think I got your point now.

If you want to check whether the automation already made the exact same comment before, you can do that as I mentioned before. Fetch all comments and match the exact string, then set the comment.

On the other hand, you can use a number custom field in order to track when did you comment on the issue. For instance, if Durval = 3 then you comment as well as set the customfield to 3. Next time you check that value accordingly.

 

if( (Durval >= 3) && (esTotalDurVal < 4) && (latestCommentValue == 3)) {  
issueInputParameters.setComment (....)
// set number custom field value to 4
issue.setCustomFieldValue(4)
}

 

Please bear in mind that this is not the exact code, you need to set custom field values using appropriate parameters.

I hope it makes sense.

sai siva November 18, 2021

@Tuncay Senturk 

thanks for the suggestion , ill try this

any chance i can work without custom fields.

Fetch all comments and match the exact string, then set the comment.
( can i have any examples for gettign comments and matchng the string ?)

soi can check for a string in the comments and make sure no duplicate comments are made?

Tuncay Senturk
Community Champion
November 19, 2021

Hi again,

Actually I wouldn't recommend that one as there are several special characters such as line feed, quote, space, end of line which might cause problems when doing exact match.

It is better to store it in a variable (here it is customfield)

Tuncay Senturk
Community Champion
November 28, 2021

@sai siva 

Did you try or do you have any update on this?

sai siva November 29, 2021

workds with a custom field ,  But as per request planning to do it within the script itself.

Suggest an answer

Log in or Sign up to answer