Posts Tagged jira

JIRA: Change Custom Field Type

I created a custom field for a project with a custom field type of Number. It quickly became evident that this should have been a Text Field instead. Unfortunately, you can’t change this in JIRA (at least not without some convoluted custom field configuration scheming).

Direct SQL access to the rescue!

First, stop JIRA before access the database directly:

--This will change the field type to text
UPDATE customfield set customfieldtypekey = 'com.atlassian.jira.plugin.system.customfieldtypes:textfield',
customfieldsearcherkey = 'com.atlassian.jira.plugin.system.customfieldtypes:textsearcher'
where cfname = '<customfield_name>';
--Find all the possible values that need to be changed
select distinct numbervalue from customfieldvalue where customfield = (select id from customfield where cfname = '<customfield_name>');
--each of these values will be included in the case statement
update customfieldvalue SET stringvalue =
case
  when numbervalue = 1 then '1'
  when numbervalue = 2 then '2'
  when numbervalue = 3 then '3'
  else stringvalue
end
where customfield = (select id from customfield where cfname = '<customfield_name>');
--Now, remove the number values that were copied to string values
UPDATE customfieldvalue set numbervalue = null where customfield = (select id from customfield where cfname = '<customfield_name>');

Now, you can start JIRA and check that everything went as planned. Once you’ve confirmed the changes, you should reindex JIRA.

Advertisements

Leave a comment

JIRA: Add watchers at issue creation

After struggling with this feature request from users for quite some time, I have a way now to add a list of watchers to an issue automatically at creation.

The secret here is (1) you need to add a scripted post function to the creation step in your workflow (so this may mean seperate workflows for individual projects) and (2) you need the Script Runner plugin.

Add the following groovy script somewhere in your CATALINA_BASE and call it in your workflow.

import com.atlassian.jira.ComponentManager

def componentManager = ComponentManager.getInstance()
def watcherManager = componentManager.getWatcherManager()
def userManager = componentManager.getUserUtil()

def watchUsers = {usernames ->
   usernames.each {
         def user = userManager.getUser(it)
         watcherManager.startWatching(user, issue.getGenericValue())
      }
}

   def users = ["comma", "separated", "usernames"]
   watchUsers(users)

Special thanks to Brian LeGros for help on this too!

18 Comments

Startup Script for JIRA in CentOS

#!/bin/sh -e
# chkconfig: 2345 90 10
# description: JIRA

# Define some variables
# Name of app ( JIRA, Confluence, etc )
APP=JIRA
# Name of the user to run as
USER=jira
# Location of application's bin directory
BIN=/opt/atlassian/jira-4/bin

case "$1" in
# Start command
start)
echo "Starting $APP "
su -s /bin/sh $USER -c $BIN/startup.sh
;;
# Stop command
stop)
echo "Stopping $APP"
su -s /bin/sh $USER -c $BIN/shutdown.sh
echo "$APP stopped successfully "
;;
# Restart command
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac

exit 0

Leave a comment