We have a custom button that we added via Script Fragments to the Release page.
We want to update a Release description field via this button.
How we can do it? Using some script\Rest endpoint or smth else?
Could you, please, advise.
Thanks.
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:getVersionID()">CUSTOMBUTTON</a>
/$
writer.write(panelOutput)
Yes, normally, your web item button should have a "link" configuration.
This will be the URL that will trigger some action.
On an issue, you could use "run code and display a flag" ... but the framework to display that flag will not be available in the context of the release page.
But the question is ... how are you selecting which release to update the description for? Or did you add the web item to "atl.jira.version.admin.operations" ?
If so you will need to somehow wire some javascript yourself against that button to call a rest api so that you can identify which release item the user clicked and pass that to the rest call..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello.
I've added a Web panel into
And It looks like this
How I can add a script to this button? Also, maybe you have an example of such script which will update\change a Description field for Release?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you've added a panel, presumably, you wrote some HTML code to display the button.
Just write some javascript that responds to the button click event.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is an example ... you'll probably want to grab the version id for the selected release. Then make an ajax call to some rest API that you'll have to create and possibly do something the API response:
def panelOutput = $/
<script>
function yourJsFunction(){
var versionId = AJS.$('#release-report-tabs-section').attr('data-version-id')
var payload = {"versionId": versionId}
AJS.$.ajax({
type: "POST",
url: "/rest/scriptrunner/latest/custom/yourRestAPI",
headers: { 'X-Atlassian-Token': 'no-check' },
data: JSON.stringify(payload),
success: function(data, status){
console.log(data);
require(['aui/flag'], function(flag) {
flag({
type: "success" ,
title: "Default description",
close: "auto",
body: "Default description added to current release"
});
});
},
error: function(data) {
console.log(data.responseText);
require(['aui/flag'], function(flag) {
flag({
type: "error" ,
title: "Error setting default description for release",
close: "manual",
body: data.responseText
});
});
}
})
}
</script>
<a class="aui-button aui-button-primary" href="javascript:yourJsFunction()">CAB</a>
/$
writer.write(panelOutput)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello. Thank you for your response. Am I right that I need to create a REST Endpoint that will update a Description field?
url: "/rest/scriptrunner/latest/custom/yourRestAPI",
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, unless there is a built-in REST Api you can use, any change you want to do permanently has to be triggered somehow on the server and that's generally done with a custom rest api.
In this case, maybe the built-in api will work for you: https://docs.atlassian.com/software/jira/docs/api/REST/8.13.9/#api/2/version-updateVersion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have some java script code already that can capture a user's action.
Javascript is a powerful development language.
Write some java script code that calls the JIRA API described in the link to make the desired change to the version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've solved it by the script above. But maybe you know how I can disable or hide this button after clicking for everyone? So we need to do only one click on this button
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the scriptrunner condition for your panel, you can include something like this:
!version.description.contains('was sent to SD by')
Then, you might want to add something in your javascript to hide the button after success.
And while you are at it, you could either force a page refresh to show the updated description or inject it with your javascript.
Something like:
var desc = "Release ID" + " " + versionId + " " + "was sent to SD by" + " " + user;
...
AJS.$('#cab-button').hide()
AJS.$('.top-level-version-info').after('<div id="description-text-content" class="version-description">' + desc + '</div>')
But you'll need to give your button an ID so you can find it easily
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.