Adding Info from History tab in Jira into ServiceNow comments

Hi there,

I am trying to figure out a way of getting the Change History information from a Jira ticket put into the ServiceNow comments. I did find the How to Sync Change History to the Text Custom Field page but it doesn’t seem to work with ServiceNow. I also asked Copilot to see if they could give me the code and it gave me the following:

def changeHistory = replica.changeHistory.collect { change ->
"Field: ${change.field}, From: ${change.from}, To: ${change.to}, Date: ${change.date}"
}.join("\n")

entity.comments += changeHistory

But it throws the following error “No such property: field for class: com.exalate.basic.domain.hubobject.v1.BasicHubChangeHistory Possible solutions: id”

I can’t seem to find any information on how to do this sadly. Any help would be much appreciated.

Hi there,
You cannot add a string value directly to entity.comments since this is a list of custom objects expecting comments.
If you want to add a comment, you refer to: addComment
You can pass the string value to this method, and it will create a comment.
Kind regards,
Ariel

1 Like

Hi there Ariel,

Thank you for your response and I think you might have fixed an upcoming issue I would have had :smiley:

The error I am getting however seems to be on the middle line of the top block. The line:

"Field: ${change.field}, From: ${change.from}, To: ${change.to}, Date: ${change.date}"

Does this look right? Will it give me what I am looking for?

More than welcome! It looks there is an issue accessing the properties of changeHistory
Please try:

    def changeHistory = replica.changeHistory.collectMany { history ->
    history.changeItems.collect { item ->
        "Field: ${item.field}, From: ${item.from}, To: ${item.to}, Date: ${history.created}"
    }
}.join("\n")

Thank you so much for getting back to me again. This sent me down the right path to getting the solution that I was looking for. Adding this to my script gave me all the history every time there was an update which made for a lot of spam quite quickly. :smiley: In the end I just grabbed the first line of the History and made a comment of that. Also I needed to stop it syncing back and filling up the comments in JIRA too. My final script was:

def changeHistory = replica.changeHistory.collectMany { history ->
    history.changeItems.collect { item ->
        "${item.field}, From: ${item.fromValue}, To: ${item.toValue}"
    }
}.join("\n")
def histFirstLine = changeHistory.split("\n")

entity.comments = commentHelper.addComment(histFirstLine.first(), false, entity.comments)

Thanks again. I don’t think I would have got there without you. ^^

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.