Create Jira Button on incident form + Integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 04:42 AM
This is the flow of the task:
1. the user click on 'Create Jira' button from the current incident.
2. After clicking on the button a pop up with a list of project with u_project_name and their relevant u_project_key is being displayed from u_jira_project table. (Both fields columns are type String).
3. Then the user can choose a project and then the current field u_jira_project (type Reference to u_jira_project_table) on the incident needs to be populated with the value that the user chose.
4. At the same time that the field u_jira_projectis being populated with value that the user chose, we need to create a ticket in Jira system using 'Jira' rest message and his 'create_bug' Post http method.
5. After creating the ticket in Jira system, the Jira system will provide a response back. We need to take this response and pull from their the id and populated the field u_jira_id on the current incident.
I already created a rest message 'Jira' with HTTP Post Method 'create_bug'.
This is the JSON Content:
{ "fields":{ "description":"${description}", "issuetype":{ "name":"Bug" }, "project":{ "key":"${project_key}" }, "summary":"${summary}", "priority":{"id":"${priority}"} } }
This is the map field for the dynamic parameters (all the fields need to pass a string values and not as sys_id) from the Content JSON:
${description} = current incident description
${project_key} = the related u_project_key of the u_project_name that the user chose from the list of project ${summary} = current incident short_description
${priority} = we need to see what is the value of the current incident priority and then do this mapping to string values: If the value is 1, need to pass string "Critical"
if the value is 2, need to pass string "High"
if the value is 3, need to pass string "Medium"
if the value is 4, need to pass string "Low
I know that this can be done using UI Action, UI Page and Script Include but Im struggling. I dont know how to do the scripting part of each section.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 06:10 AM
Hi @Alon Grod ,
Here's an example of how you can achieve this using a UI Action, UI Page, and Script Include:
->> UI Action:
// Name: Create Jira
// Table: incident
// Form Button: true
// Action name: create_jira
(function executeAction() {
// Get the current incident record
var gr = new GlideRecord('incident');
if (!gr.get(current.sys_id)) {
gs.addErrorMessage("Could not find the current incident record");
return;
}
// Define the UI action window properties
var dialog = new GlideDialogWindow('create_jira');
dialog.setTitle('Create Jira');
dialog.setPreference('incident_sys_id', current.sys_id);
dialog.render();
})();
->> UI Page:
// Name: Create Jira
// Table: incident
// Form Button: true
// Action name: create_jira
(function executeAction() {
// Get the current incident record
var gr = new GlideRecord('incident');
if (!gr.get(current.sys_id)) {
gs.addErrorMessage("Could not find the current incident record");
return;
}
// Define the UI action window properties
var dialog = new GlideDialogWindow('create_jira');
dialog.setTitle('Create Jira');
dialog.setPreference('incident_sys_id', current.sys_id);
dialog.render();
})();
->> Script Include:
var JiraRestAPI = Class.create();
JiraRestAPI.prototype = Object.extendsObject(AbstractAjaxProcessor, {
createBug: function() {
var incidentSysId = this.getParameter('sysparm_value').incident_sys_id;
var projectKey = this.getParameter('sysparm_value').project_key;
this.jiraRestMessage = 'Jira'; //Name of the REST message you created
var gr = new GlideRecord('incident');
if (!gr.get(incidentSysId)) {
return null;
}
var priority;
switch (gr.priority) {
case '1':
priority = 'Critical';
break;
case '2':
priority = 'High';
break;
case '3':
priority = 'Medium';
break;
case '4':
priority = 'Low';
break;
default:
priority = 'Medium';
}
var description = gr.getValue('description');
var summary = gr.getValue('short_description');
var requestBody = {
fields: {
description: description,
issuetype: {
name: 'Bug'
},
project: {
key: projectKey
},
summary: summary,
priority: {
name: priority
}
}
};
var response = sn_ws.RESTMessageV2.get(this.jiraRestMessage).setRequestBody(JSON.stringify(requestBody)).execute();
var responseBody = response.getBody();
var jiraId = JSON.parse(responseBody).id;
//return or set jiraId to variable/field..
},
type: 'JiraRestAPI'
};
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2023 12:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 04:25 AM
Hi @Alon Grod ,
Did you happen to achieve this, we got the same requirement so please let me know the steps you followed to achieve this.
Thanks in advance