Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add labels to a Jira through javascript?

Devi Foskett January 16, 2019 edited

I am trying to make a google extension that will add labels when you click one button. It is also supposed to add a subtask as well. I am stuck at the point where I do not know how to get the labels to be applied to the page.

JSON:

{ 
"name":"Jira Extension",
"version":"1.0",
"description":"Allow for quick access to changing SD and TA",
"permissions":[
"activeTab"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background":{
"persistents": false,
"scripts": ["background.js"]
},
"options_page":"options.html",
"manifest_version":2
}

 HTML:

<input id="scYes" class="submit" type="submit" name="scyes" value="SC Yes">
<input id="scNo" class="submit" type="submit" name="scno" value="SC Yes">

Javascript&colon;

window.onload = function(){
document.getElementById('scYes').onclick = function(){
var label = '{ "labels" :["Sd_reviewed", "Ta-reviewed", "Reviewed", "Functional"] }';
var myObj = JSON.parse(label);
document.getElementById("demo").innerHTML = myObj.labels;
};
document.getElementById('scNo').onclick = function(){
var test = '{ "labels" :["Reviewed", "Technical"] }';
var myObj = JSON.parse(test);
document.getElementById("demo").innerHTML = myObj.labels;
};
}

The scYes is simply a button to confirm that the user would like to add the labels. I am not very experience with Json or Javascript 

2 answers

0 votes
Gabriel O
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 21, 2021

Here's how I did it

 

// ==UserScript==
// @name Jira autolabel
// @namespace jira
// @version 0.1
// @description Add label when creating JIRA issue automatically
// @author Gabriel Ostrolucký
// @match https://jira.check24.de/*
// @icon https://jira.check24.de/favicon.ico
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js

// @run-at document-end
// ==/UserScript==

const autoLabel = 'sep-cdn-and-environments';

waitForKeyElements('#labels', (el) => {
if ($('#project').val() !== '24000') {
return;
}

el.append(jQuery(`<option value="${autoLabel}" selected="selected" />`));
$('#labels-multi-select .representation .items').append(jQuery(`
<li id="item-row-1" class="item-row" role="option">
<button type="button" tabindex="-1" class="value-item">
<span class="value-text">${autoLabel}</span>
</button>
<em class="item-delete" onclick="
$('option[value=${autoLabel}]').remove();
$('#labels-multi-select .representation .items #item-row-1').remove();
"/>
</li>
`));
});
0 votes
Jarrod Moura
Contributor
December 12, 2019

Hi @Devi Foskett , did you figure this out?

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events