- 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:05 AM
Just add current.update() in your code. Since Async business rules after the crud operation have been performed and take some time to execute. you need to use current.update to update values whereas Before business rules runs before any crud operation is performed on Database therefore it got update or inserted by default.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2023 06:24 AM
Hi Mehta,
Thanks for quick response. It work for me 🙂
Regards,
Madhu.
- 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: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!