J tricks - Little JIRA Tricks
  • Home
  • Plugins ↓
    • JQL Tricks Plugin
      • JQL Tricks Plugin - Cloud
        • JQLT Cloud Installation
        • JQLT Cloud Configuration
        • JQLT Cloud Usage
        • JQLT Cloud License
        • JQLT Cloud FAQ
      • JQL Tricks Plugin - DC
        • JQLT DC Installation
        • JQLT DC Configuration
        • JQLT DC Usage
          • JQLT Issue Functions
          • JQLT Subtask Functions
          • JQLT Links Functions
          • JQLT Development Functions
          • JQLT Worklog Functions
          • JQLT Project Functions
          • JQLT Component Functions
          • JQLT Version Functions
          • JQLT Group Functions
          • JQLT User Functions
          • JQLT Date Functions
        • JQLT DC License
        • JQLT DC FAQ
        • JQLT DC Known Issues
        • JQLT DC Performance
      • JQL Tricks Cloud Migration
    • Simplified Planner
      • J-Planner Installation
      • J-Planner Configuration
      • J-Planner Usage
        • Creating a plan
        • Editing a plan
        • Deleting a plan
        • Viewing a plan
        • Modifying a plan
      • J-Planner FAQ
    • Atla-Search Plugin
      • Atla-Search Installation
      • Atla-Search Configuration
      • Atla-Search Usage
      • Atla-Search License
      • Atla-Search FAQ
    • Heroku for Compass App
      • Heroku for Compass Installation
      • Heroku for Compass Configuration
      • Heroku for Compass Usage
    • Datadog for Compass App
      • Datadog for Compass Installation
      • Datadog for Compass Configuration
      • Datadog for Compass Usage
    • Copy to subtask Plugin
    • All Plugins
  • Tutorials
  • The Book
  • Contact Us
  • Home
  • Plugins ↓
    • JQL Tricks Plugin
      • JQL Tricks Plugin - Cloud
        • JQLT Cloud Installation
        • JQLT Cloud Configuration
        • JQLT Cloud Usage
        • JQLT Cloud License
        • JQLT Cloud FAQ
      • JQL Tricks Plugin - DC
        • JQLT DC Installation
        • JQLT DC Configuration
        • JQLT DC Usage
          • JQLT Issue Functions
          • JQLT Subtask Functions
          • JQLT Links Functions
          • JQLT Development Functions
          • JQLT Worklog Functions
          • JQLT Project Functions
          • JQLT Component Functions
          • JQLT Version Functions
          • JQLT Group Functions
          • JQLT User Functions
          • JQLT Date Functions
        • JQLT DC License
        • JQLT DC FAQ
        • JQLT DC Known Issues
        • JQLT DC Performance
      • JQL Tricks Cloud Migration
    • Simplified Planner
      • J-Planner Installation
      • J-Planner Configuration
      • J-Planner Usage
        • Creating a plan
        • Editing a plan
        • Deleting a plan
        • Viewing a plan
        • Modifying a plan
      • J-Planner FAQ
    • Atla-Search Plugin
      • Atla-Search Installation
      • Atla-Search Configuration
      • Atla-Search Usage
      • Atla-Search License
      • Atla-Search FAQ
    • Heroku for Compass App
      • Heroku for Compass Installation
      • Heroku for Compass Configuration
      • Heroku for Compass Usage
    • Datadog for Compass App
      • Datadog for Compass Installation
      • Datadog for Compass Configuration
      • Datadog for Compass Usage
    • Copy to subtask Plugin
    • All Plugins
  • Tutorials
  • The Book
  • Contact Us

JIRA notification messages

12/8/2013

12 Comments

 
Ever wondered how the nice little JIRA notification messages are created? The ones you get when an issue is created in JIRA?
Picture
Doing this is so easy that you will want to try it out in every new plugin that you write!

All you need is to inject the following javascript snippet into the page:

JIRA.Messages.showSuccessMsg('Your message goes here');

Let me show you a simple demonstration of this. I am going to put this into the announcement banner so that I don't have to create a plugin to inject this javascript ;)

Let us say we need to show this message when a user visits the profile. All you need to do is to add this snippet in the Announcement banner.

<script >
var pathname = window.location.pathname;
if (pathname.indexOf("ViewProfile.jspa") >= 0)
{
   JIRA.Messages.showSuccessMsg('You are viewing your profile, Success');
}
</script>


And the message will appear on the screen when you visit the profile.

Picture
But, did you notice that the message didn't have a close button as you normally see in the Create notification? This is where you can pass properties to the function.

<script >
var pathname = window.location.pathname;
if (pathname.indexOf("ViewProfile.jspa") >= 0)
{
   JIRA.Messages.showSuccessMsg('You are viewing your profile', {closeable: true});
}
</script>


Here we passed the closeable property to the same function and the message will now have a close option.
Picture
Now, you can replace the showSuccessMsg function with showErrorMsg or showWarningMsg to get the appropriate message format.
Picture
ERROR
Picture
WARNING
In all the 3 cases, the message disappears itself after the default timeout of 10 seconds. If you need a bigger timeout, use the timeout property.

<script >
var pathname = window.location.pathname;
if (pathname.indexOf("ViewProfile.jspa") >= 0)
{
   JIRA.Messages.showSuccessMsg('You are viewing your profile', {closeable: true, timeout: 60});
}
</script>


Are there any other properties? The only other property is type and you can use it when you use the generic function showMsg instead of showSuccessMsg, showErrorMsg or showWarningMsg. The possible type values are SUCCESS, ERROR or WARNING.

For example:

JIRA.Messages.showSuccessMsg('You are viewing your profile', {closeable: true, timeout: 60});

is same as

JIRA.Messages.showMsg('You are viewing your profile', {type: SUCCESS, closeable: true, timeout: 60});

For more details on how these functions work and for more more useful functions like showReloadSuccessMsg, take a look at includes/jira/common/messages.js file. Hope you find it useful.

PS: If you find these little tutorials useful, you might also like the JIRA Development Cookbook.
12 Comments
Joel Holmberg
7/2/2014 01:52:41 am

"so that I don't have to create a plugin to inject this javascript ;)"

That's really the hard part here, so I'm sorry to say, this "tutorial" is not very helpful.

Basically your saying "I'm going to show you how to call the message box from your plugin - so here's how you do it from the Announcement Banner ..."

Reply
J-Tricks
7/3/2014 03:46:24 am

Sorry you felt that way. I always try to keep it really simple and address one specific issue at a time. Most plugin developers already know how to inject javascript into a plugin because it is a module in itself. Just google and you will find out ;)

Here is the module details if you like: https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module

Reply
Dennis
1/27/2015 10:46:14 pm

HI, is it also possible to trigger a banner by workflow transition ? I'de like to setup a reminder for people like "Don't forget to log your time" when switching from in Progress to Resolved and from Test to Closed.

Reply
J-Tricks
1/28/2015 01:38:20 am

You can, by adding some javascripts on the screen (via field descriptions or something).

But a better, and easier, approach is to use the "Message" custom fields from JIRA Toolkit plugin. See https://ecosystem.atlassian.net/wiki/display/JTOOL/JIRA+Toolkit+Plugin

Reply
Srini Chimata
2/11/2015 04:34:32 pm

Starting from Jira v5.2.5, the Toolkit posed a problem and we had a tough time with all custom velocity (edit) fields as these fields were not present in the next version Toolkit plugin.. they thought that the velocity (edit) fields were causing a security threat to Jira.

The best way to execute the JavaScript snippets is to put them in the Description section of the Custom field.

Kim
6/10/2015 07:59:58 pm

Hi,

Thank you for cool tutorials for JIRA!
Just one question appeared: is it still working for new JIRA version 6.4.x ? And if yes would you please explain how should I implement this JavaScript in my plugin?

I'm creating an EventListener. It is working fine intercepting all the events and doing some things on events. Also I created web-resource referencing to my new pop-up.js file. This .js file contains
<script>
JIRA.Messages.showSuccessMsg('Hi there')
</script>

And in my EventListener I'm calling ComponentAccessor.getWebResourceManager().requireResource("my.atlassian.plugin.jahandler:pop-up");
But it is not working = (

Reply
J-Tricks
6/12/2015 03:39:39 am

You can't load the web resource in a listener because listener is a separate thread. How is the javascript invoked? From which action?

Reply
Prakash
12/9/2016 11:33:14 pm

Is you issue addressed. I am working on the same scenario with event listener. How to post a message after the event handling succeeded or failed

Reply
Tom
6/15/2015 05:27:15 am

I would like to show a system maintenance warning message on a "User login" event. Is this possible or can I just invoke these messages on certain pages in Jira?
Is it easy to catch a "Logon event"? Would you have some entry point for me where I can start the research?

Reply
J-Tricks
6/15/2015 03:31:59 pm

I'm sure you know about the announcement banner. Have you tried adding a javascript in there? You will have to mark the message as read and handle that in the session.

Reply
Tom
6/17/2015 05:02:03 am

Sure, I also placed your example scripts in the announcement banner and they work fine (show message on user profile page). What I don't want to do is to place a maintenance announcement there.
How would I trigger this kind of messages on a user login event?

zac
3/8/2016 01:12:18 am

Thanks, its indeed a great tutorial for a beginner. Couldn't find any help on the net for few hours.

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Enter your email address:

    Author

    Jobin Kuruvilla - Works in Adaptavist as Head of DevOps Professional Services. 

    Author of JIRA Development Cookbook and JIRA 5.x Development Cookbook.


    RSS Feed

    Categories

    All
    Acive Objects
    Ajs
    Book
    Components
    Condition
    Custom Fields
    Customization
    Events
    Gadgets
    Javascript
    Jql
    Listener
    Mail
    Permissions
    Plugin Framework
    Post Function
    Properties
    Remote Invocation
    Reporting
    Rest
    Scheduled Tasks
    Search
    Services
    Soap
    Summit
    User Interface
    Validator
    Webwork Actions
    Workflow

    Archives

    October 2016
    August 2016
    March 2016
    January 2016
    December 2015
    May 2014
    December 2013
    November 2013
    July 2013
    June 2013
    April 2013
    October 2012
    September 2012
    August 2012
    July 2012
    May 2012
    March 2012
    February 2012
    January 2012
    December 2011
    November 2011
    June 2011
    May 2011
    April 2011
    March 2011
    February 2011
    January 2011
    November 2010
    October 2010
    September 2010
    August 2010

SUPPORT
APPS
TUTORIALS
THE BOOK
© J-Tricks