# Status change in service now does not trigger status change in Jira

**URL:** <https://community.exalate.com/t/status-change-in-service-now-does-not-trigger-status-change-in-jira/5188>\
**Category:** General Questions\
**Tags:** exalate, servicenow-jira, jiraserver, migrated\_question\
**Created:** [November 4, 2024, 7:48am UTC](https://community.exalate.com/t/status-change-in-service-now-does-not-trigger-status-change-in-jira/5188 "2024-11-04T07:48:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:48am UTC](https://community.exalate.com/t/status-change-in-service-now-does-not-trigger-status-change-in-jira/5188/1 "2024-11-04T07:48:49Z")

</div>

_Originally asked by Harold Oconitrillo on 27 April 2022 [(original question)](https://oldcommunity.exalate.com/questions/42837274)_

* * *

Hello,

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

Outgoing code for service-now:

```auto
  replica.state = entity.state

```

Incoming Jira code:

```auto
    // 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!

* * *

#### Comments:

> **Harold Oconitrillo commented on 27 April 2022**
>
> > Hi,
> 
> You may review the documentation below and check the incoming rules.
> 
> [https://docs.idalko.com/exalate/x/jgF1Aw](https://docs.idalko.com/exalate/x/jgF1Aw)
> 
> Feel free to contact e back if you have any further question.
> 
> Thanks.

> **Serhiy Onyshchenko commented on 01 May 2022**
>
> > Hey, Harold Oconitrillo , what happens if you remove the mapping from the script:
> 
> ```auto
> // 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
> 
> ```auto
> issue.setStatus("Done/Resolved")
> 
> ```
> 
> part  
> Regards, Serhiy.

> **Serhiy Onyshchenko commented on 01 May 2022**
>
> > And another question: isn’t
> 
> ```auto
> } 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
> 
> ```auto
> issue.setStatus("...")
> 
> ```
> 
> ?  
> Regards, Serhiy.

> **Mihai Arama commented on 02 May 2022**
>
> > Hi Serhiy Onyshchenko ,
> 
> Thank you for your reply!
> 
> I removed the status mapping, so the script is now:
> 
> ```
> def remoteStatusName \= replica.state  
> 
> ```
> 
> ```auto
> 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

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:48am UTC](https://community.exalate.com/t/status-change-in-service-now-does-not-trigger-status-change-in-jira/5188/2 "2024-11-04T07:48:50Z")

</div>

_Answer by Serhiy Onyshchenko on 04 May 2022_

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

```auto
issue.setStatus("Backlog")

```

Which effectively reverted the results of the original setStatus.

* * *
