Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to add Web-Panel to Postfunction?

I was following this tutorial:

Adding content to the Jira View Issue page (atlassian.com)

I was able to create a WebPanel . So whenever a new Issue is created there will be a WebPanel. 

That is not what I want. Instead I want the WebPanel only be created and visible when a certain transition is executed. At the end  what happened in the transition will be shown as a message in the web panel.

Is there any way to do this ? 

 

 

1 answer

0 votes

A post-function is a set of actions taken when an issue has a transition confirms.  It has nothing to do with the view of an issue, and it's too late in the process of transitioning to ask the human for anything.  

It's absolutely not "adding a panel to a post-function".  But "adding a display dependent on data that a post-function has written" is possible with a bit of code.  You'll need to code something that can write some data to the issue (in the post-function), then detect that this new data is there, and then (conditionally) add a web-panel to the issue view.

I know I can do this with writing an app to provide those components, and Scriptrunner can do it too (there may be other apps that can provide all the components,but as an adaptavist, I tend to have DR on tap, so I'm not familiar with others).

I'm fuzzy on the exact need, but https://library.adaptavist.com might be able to show you a few things that could help (even if you have no SR, it's not bad for some principles of where things happen in Atlassian stuff)

Thanks. So as I said I created a Web Panel. This is visible not in every single issue at the right bottom corner.  How can I update the text of this Web Panel from my plugin Postfunction ?? Or if that not possible how can I show some status messages in an issue after returning from a post function ?

What have you put in the web-panel?   

A common usage is to put a custom field in them, or a display based on existing fields (almost a "scripted field").  So to "update" your panel, you would write data into the issue fields and the panel would display them or a calculation.

My Web Panel ist just a text . And I just want to update this text in the postfunction. Sounds pretty easy. But hard to implement. 

I did not know that you could put customfield in Web Panel. Sounds interesting. Customfields I could fetch in my postfunction I guess. How can I add customField to Web Panel ?? Web Panel is only defined in xml .

Do you know how to put a customField in a Web Panel ? I cannot find any tutorial for this.

For my task I cannot use ScriptRunner. I outsourced my code to a Jira Plugin . There I created a postfunction module. All Java Code. Inside this postfunction I need to change the text of the Web Panel.  I need a detailed description how to do that.

 

P.S. The link you sent me suggests to use "Show a web panel built-in script". But this seems to be associated with costs. At least I cannot see this in my list of available postfunctions in my Jira System .

Ah, sorry, I got too focussed on SR and didn't re-read the question properly before my last post.

The tutorial you used to create your web-panel shows you how to create a panel with some text that is calculated from some system and issue data (the current date and the due-date on the issue).  

Now, that is not "adding a web panel to a post-function", but you can't do that anyway, as a post-function is a process that happens during a transition, it has nothing to do with the UI and post-functions fo not show anything to the users.

So my point was that you can set data on the issue with a post function, and then, when the issue is viewed later, your web-panel can pull out that data and display it.

Assuming the post-function writes its data to customfield_12345, then you can extract and display that.  (I believe there is a way to just explicitly say "show this field in this panel", but I've never tried to do that, my panels have all been calculations)

To do it the "extract and show" way, compare the code in java (step 5) with the velocity in step 6.  You'll see the velocity says $daysAwayFromDueDate a few times, and the java says contextMap.put("daysAwayFromDueDate", daysAwayFromDueDateCalc); - that's how the java feeds data to the panel, and how the panel reads it out of the data it gets.

You could simplify both down to almost just those two statements!  If your velocity said nothing more than

$myField

then the important line of java could be as simple as

contextMap.put("myField", currentIssue.getCustomFieldValue(customFieldManager.getCustomFieldObjects(issue).findByName("The field name"));

I say "simple", I'm doing everything on one line there and making a lot of assumptions, like the field is always there, the content human readable etc.  The code at https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console is a really good example of how to read various types of field, and far better than anything I'd write.  Even though it's in Groovy, you'll be able to see how various Java imports give you things like customFieldManager and how to convert data from Jira storage to human-usable.

You wrote:

So my point was that you can set data on the issue with a post function, and then, when the issue is viewed later, your web-panel can pull out that data and display it.

 

So basically you mean one should define a hidden custom field on the issue. Postfunction will write messages to this custom field. And the web panel later can retrieve this information from the hidden custom field. Sounds good. But first I do not know if you can have hidden custom fields. Second I do not know if I can refresh the page to have the web panel be redrawn with the new text.

Correct.

You don't have to have hidden custom fields, you can show them if you want.  You don't have to though, to hide them, just don't put them on any screens (view especially)

You won't need to worry about refreshing - remember the post-function you're running is on a transition, which refresh the page anyway.

I followed your solution. The problem I have not inside the Web Panel class I cannot access the issue. 

public class MessageBox extends AbstractJiraContextProvider {

private final Logger logger = LoggerFactory.getLogger(MessageBox.class);

@Override
public Map getContextMap(ApplicationUser applicationUser, JiraHelper jiraHelper) {
Map<String, Object> contextMap = new HashMap<>();

Optional<CustomField> steps = getCustomfieldByName("ToBeDeleted");

if(steps.isPresent()) {

contextMap.put("daysAwayFromDueDate", steps.get().toString());
logger.error("Panel: "+steps.get().toString());
}
else
{
contextMap.put("daysAwayFromDueDate", "Did not work!");
logger.error("Panel: "+"Did not work");
}

return contextMap;
}
}

I need an issue to get the actual value. Normally it would be coded like that:

Object someString= issue.getCustomFieldValue(steps .get());

 But in web panel issue is not passed

After some searching I found the answer.

Issue issue = (Issue) jiraHelper.getContextParams().get("issue");

 

Using jiraHelper you get the issue. Really complicated. Why this time you get jiraHelper and not issue passed.

 

But now it seems to work. Thanks a lot for your help.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you