Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get transition ID to update status in the script using Rest API.

Hi Team,

I am trying to update Jira status. This should reflect in Servicenow with the Transition ID mapping using scripted rest API.

 

Integration between Servicenow -> Jira : We achieved this with servicenow Business rules.

Integration between Jira-> Servicenow: We achieving field Mapping using Servicenow Scripted rest API.

Using the Scripted Rest API, we have mapped few fields as required. (Like Summary, Description,severity.... ).

 

Now using the following script we would like to Map Jira Status with the Servicenow State field.

Fyi...

PFB for the Jira to SNOW state mapping we are referring.

Jira Transition IDsServicenow State Values
312
513
1018
1116

 

PFB for the Scripted Rest API we were Trying ..

Please Help how to define Transition ID to fetch as similar to Summary and other fields ...and correct my script... 

 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var sLog = '';

var pathParams = request.pathParams;
var operation = pathParams.operation; //'myApp_table'
var issueId = pathParams.id; //'1234'
sLog += "\n operation=" + operation;
sLog += " \n id=" + issueId;
var issueDetails = '';
issueDetails = getIssueDetails(issueId);
//sLog += '\n IssueDetails=' + issueDetails;
var issueJson = JSON.parse(issueDetails);
var issueSummary = issueJson.fields.summary;
var transID = issueJson.transitions.transitions.fields.id;
//var tranId = $("input[name='action']").attr("value");
//var transState = pathParams.transID;

gs.warn('--->' + issueJson.fields);

if (operation.indexOf('JiraIssueCreation') > -1) {
createIncident(issueId, issueSummary);
}

function createIncident(issueId, issueSummary) {
var grInc = new GlideRecord('incident');
grInc.addEncodedQuery('correlation_id=' + issueId);
grInc.query();
if (grInc.next()) {
grInc.short_description = issueSummary;
// grInc.description = issueDesc;
grInc.correlation_id = issueId;
grInc.correlation_display = issueJson.key;
grInc.severity = issueSeverity.split(' ')[1];
grInc.u_jira_environment = issueEnvironment;

// grInc.assignment_group = '83051eb2db58b0506854d855ca961968';

switch(transID) {
case '31':
grInc.state='2';
break;

case '51':
grInc.state='3';
break;

case '101':
grInc.state='8';
break;

case '111':
grInc.state='6';
break;
}

grInc.update();
} else {
grInc.initialize();
grInc.short_description = issueSummary;
// grInc.description = issueDesc;
grInc.correlation_id = issueId;
grInc.correlation_display = issueJson.key;
grInc.severity = issueSeverity.split(' ')[1];
grInc.u_jira_environment = issueEnvironment;
grInc.insert();
}
}

function getIssueDetails(issueID) {
try {
var r = new sn_ws.RESTMessageV2('JiraIntegrationEndpoint', 'Get Issue Details');
// r.setStringParameterNoEscape('issueID', 'SE-23');
r.setStringParameterNoEscape('issueID', issueID);
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
//gs.log('Status:'+ response.getBody());
return responseBody;
//return JSON.stringify(request.body.data) ;
//gs.log(JSON.stringify(request.body.data));


}

})(request, response);

 

 

1 answer

0 votes
Daniel Eads Atlassian Team Jul 08, 2021

Hi @sriharsha m, welcome to the Community!

To transition an issue between statuses in Jira through the API, you would make a POST request to the URL path like this (substituting in your site and the issue key):

https://{yoursite}.atlassian.net/rest/api/3/issue/{issueIdOrKey}/transitions

The transition ID you want to use goes in the body of the request, as an object called transition with a key of id. For example:

  "transition": { "id": "5" } 

A full sample request is available in the REST API documentation showing how to call a transition .

 

How do you find which transition IDs you can use? A GET request to the same URL! Here's the REST API documentation for getting the valid transitions . For clarity, that's just a GET to the same URL that you would make the POST request to for the actual update. Substitute in your site URL and issue key:

https://{yoursite}.atlassian.net/rest/api/3/issue/{issueIdOrKey}/transitions

Let me know if you need further clarification!

Cheers,
Daniel | Atlassian Community

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira Service Management

Atlympic Event: Jira Service Managemnt

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

94 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you