- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 05:52 AM
Hi All ,
Good evening
My query is I am fetching the Jira key, id, and statuscode from the response body and updating the same values in the below incident form.
I have create Async business rule, code is below
(function executeRule(current, previous /*null when async*/ ) {
var req_boby = "{\"fields\":{\"project\":{\"key\":\"JIR\"},\"summary\":" + "\"" + current.short_description + "\",\"issuetype\": {\"name\": \"Task\"}}}";
var request = new sn_ws.RESTMessageV2('Snow_to_JIRA_Integration', 'CreateIncident');
request.setEndpoint('https://sagaras400.atlassian.net/rest/api/3/issue');
request.setHttpMethod('POST');
request.setRequestBody(req_boby);
request.setBasicAuth('sagaras400@gmail.com', 'ATATT3xFfGF0TImb89VZ_qdM8n1Co38t8XIPX2VTT9Aty25np9s_frBWdwguGMry7y0ceVpdjUGVNNjv7q7jFQYvFBQUcwqudY7ndyE1j_QWebD9rIlVv1o4zYQd-0o95YlIuL4Ct701bnxroIBNK-Ot2jYMTkzDN8ay8tcewZHbDQTxGI7yDag=E3CB3A77');
request.setRequestHeader('Accept', "application/json");
request.setRequestHeader("Content-Type", "application/json");
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var body = JSON.parse(responseBody);
// current.setValue('u_key',body.key);
// current.setValue('u_id',body.id);
// current.setValue('u_httpstatuscode',response.getStatusCode());
current.u_key = body.key;
current.u_id = body.id;
current.u_httpstatuscode = httpStatus;
current.u_jirakey = body.key;
gs.log(body.id);
gs.log(body.key);
gs.log(httpStatus);
})(current, previous);
But the values are not updating in the incident form. I used current.field = PassValue and current.setValue() both methods however it is not working.
But the values I can captured in system log, because I used gs.log()
JIRA :
I would request please let me know what was wrong in my code.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 06:08 AM - edited 04-05-2023 06:17 AM
I think you have missed current.update in your script
As you have set all the values, you need to mention "current.update()", just to update the record
current.u_key = body.key;
current.u_id = body.id;
current.u_httpstatuscode = httpStatus;
current.u_jirakey = body.key;
current.update();
Meanwhile, you have written a correct script, happy coding 🙂
Please mark this answer as helpful + accept it if it has answered your query!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 06:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 06:26 AM
Hi @Madhusagar Pal1 ,
happy that it worked out for you.
Can you mark my answer as correct or helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 06:30 AM
Yes Mehta ,
before current.update () we need to use current.setWorkFlow(false). Otherwise it is going into infinite loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 06:32 AM - edited 04-05-2023 06:32 AM
This would be the case with : After - update business rule
for async it should work fine without setWorkflow()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 06:30 AM
I have also answered correctly your query on the same time, it just a clash of few seconds
Meanwhile! you can accept multiple solutions for a question