Forums

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

Update description field for Release using JQuery and button

Alexander August 11, 2021

Hello. We have a script want we want to use to upgrade a Description field for Releases by clicking on the custom button (added via Script Fragment).

But nothing happens when we add this script to the button and click.

Need some help to fix it, please.

 

def panelOutput = $/
<script>
function getVersionID()
{
var versionId = AJS.$('#release-report-tabs-section').attr('data-version-id')
var user;
AJS.$.ajax({
url: "/rest/gadget/1.0/currentUser",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data.username;
}
});
var dataObject = {"update":{"description":[{"edit":{"Updated by" user}}]}};
AJS.$.ajax({
type: 'PUT',
contentType: 'application/json',
url: "/rest/api/2/version/" + versionId,
dataType: 'json',
async: false,
data: JSON.stringify(dataObject),
success: function(response){ alert("yes"); },
error: function(error){ alert(JSON.stringify(error)); }
});
}
</script>
<a class="aui-button aui-button-primary" href="javascript&colon;getVersionID()">CUSTOMBUTTON</a>&nbsp;
/$
writer.write(panelOutput)

3 answers

0 votes
Alexander August 19, 2021

Any updates?

0 votes
Alexander August 12, 2021

I've solved it by the script above. But maybe somebody know how I can disable or hide this button after clicking for everyone? So we need to do only one click on this button

0 votes
Alexander August 12, 2021

I've solved this. If anybody is interested

def panelOutput = $/
<script>
function getVersionID()
{
var versionId = AJS.$('#release-report-tabs-section').attr('data-version-id');
var user;
AJS.$.ajax({
url: "/rest/gadget/1.0/currentUser",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data.fullName;
}
});
var datos = {"description":"Release ID" + " " + versionId + " " + "was sent to SD by" + " " + user};

var parameters = JSON.stringify(datos);
AJS.$.ajax({
url: "/rest/api/2/version/" + versionId,
type: "PUT",
contentType: 'application/json',
data: parameters,
dataType: 'json',
async: false,
processData: false,
success: function(data, status){
var myFlag = AJS.flag({
type: 'success',
body: "Release ID" + " " + versionId + " " + "was sent to SD by" + " " + user,
});
},
error: function(error){
alert(JSON.stringify(error));
}
});
}
</script>
<a class="aui-button aui-button-primary" href="javascript&colon;getVersionID()">CUSTOMBUTTON</a>&nbsp;
/$
writer.write(panelOutput)

Suggest an answer

Log in or Sign up to answer