2
1
0

Hello,

We have a connection between Jira (on-premise) and Service-Now.

Outgoing code for service-now:

  replica.state = entity.state

Incoming Jira code:

    // status mapping & status related changes
    def statusMapping = ["Closed (resolved)":"Done/Resolved"]
    def remoteStatusName = replica.state
 
    if (!replica.state.equals(previous?.state)) {
        if (remoteStatusName == "Closed (resolved)") {
            statusCommentString = "Current Service-Now state: " + " *" +  replica.state + "*" + "\n" + "Previous Service-Now state: " +  " *" + previous?.state + "*"
            issue.comments = commentHelper.addComment(statusCommentString, issue.comments)
            issue.setStatus(statusMapping[remoteStatusName] ?: remoteStatusName)
        } else {
        statusCommentString = "Current Service-Now state: " + " *" +  replica.state + "*" + "\n" + "Previous Service-Now state: " +  " *" + previous?.state + "*"
        issue.comments = commentHelper.addComment(statusCommentString, issue.comments)
        }
    }

In Service-Now we have 2 ways of getting to the “Closed (resolved)” state. One transition is called “Closed”, and the other one is called “Ready to Close”. After both, the state of the service-now ticket reaches “Closed (resolved)”, the difference beeing some different mandatory fields being filled in before doing the transition, and triggering a checkbox after the action, or not.

When we do the “Closed” transition in service-now, the Jira ticket gets transitioned to “Done/Resolved”.

When we do the “Ready to Close” transition in service-now, the Jira ticket does NOT get transitioned, although the comment is left as expected with the previous and current status. There are no errors, but it just does not happen.

Please let me know if you need any additional details from our side.

Thank you!

  1. Harold Oconitrillo

    Hi,

    You may review the documentation below and check the incoming rules.

    https://docs.idalko.com/exalate/x/jgF1Aw 

    Feel free to contact e back if you have any further question.

    Thanks.

  2. Serhiy Onyshchenko

    Hey, Harold Oconitrillo , what happens if you remove the mapping from the script:

        // status mapping & status related changes
        def remoteStatusName = replica.state
     
        if (!replica.state.equals(previous?.state)) {
            if (remoteStatusName == "Closed (resolved)") {
                statusCommentString = "Current Service-Now state: " + " *" +  replica.state + "*" + "\n" + "Previous Service-Now state: " +  " *" + previous?.state + "*"
                issue.comments = commentHelper.addComment(statusCommentString, issue.comments)
                issue.setStatus("Done/Resolved")
            } else {
            statusCommentString = "Current Service-Now state: " + " *" +  replica.state + "*" + "\n" + "Previous Service-Now state: " +  " *" + previous?.state + "*"
            issue.comments = commentHelper.addComment(statusCommentString, issue.comments)
            }
        }

    Note the 

    issue.setStatus("Done/Resolved")

    part
    Regards, Serhiy.

  3. Serhiy Onyshchenko

    And another question: isn't

    } else {
            statusCommentString = "Current Service-Now state: " + " *" +  replica.state + "*" + "\n" + "Previous Service-Now state: " +  " *" + previous?.state + "*"
            issue.comments = commentHelper.addComment(statusCommentString, issue.comments)
    }

    supposed to have an

    issue.setStatus("...")

    ?
    Regards, Serhiy.

  4. Mihai Arama

    Hi Serhiy Onyshchenko ,


    Thank you for your reply!


    I removed the status mapping, so the script is now:


        def remoteStatusName = replica.state
     

        def remoteStatusName = replica.state
     
        if (!replica.state.equals(previous?.state)) {
            if (remoteStatusName == "Closed (resolved)") {
                statusCommentString = "Current Service-Now state: " + " *" +  replica.state + "*" + "\n" + "Previous Service-Now state: " +  " *" + previous?.state + "*"
                issue.comments = commentHelper.addComment(statusCommentString, issue.comments)
                issue.setStatus("Done/Resolved")
            } else {
            statusCommentString = "Current Service-Now state: " + " *" +  replica.state + "*" + "\n" + "Previous Service-Now state: " +  " *" + previous?.state + "*"
            issue.comments = commentHelper.addComment(statusCommentString, issue.comments)
            }
        }


    The same happens, it only works for one transition, but not for the other. The comment still gets added, but the "issue.setStatus("Done/Resolved") part does not get set.


    The second "issue.setStatus" in the 'else' clause is not needed, because we only want to change the status of the Jira issue if the service now one is "Closed (resolved)", not if it is still active or pending other info.


    Please let me know if you have any suggestions.

    Thank you!

    Mihai

CommentAdd your comment...

1 answer

  1.  
    2
    1
    0

    We had a short call with Mihai Arama 

    And we figured out that later on after that snippet there was a conditional statement which led to

    issue.setStatus("Backlog")

    Which effectively reverted the results of the original setStatus.

      CommentAdd your comment...