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.
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..
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?
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.
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)
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)
It looks like you're new here. Sign in or register to get started.