Store execution time to Custom Field

Stores execution time of transition into customfield.

public class StoreExecutionTime implements FunctionProvider{
	private FieldManager fieldManager;

	private static final Category log = Category.getInstance(StoreExecutionTime.class);

	public void execute(Map transientVars, Map args, PropertySet ps) {

	GenericValue issue = (GenericValue)transientVars.get("issue");
        String fieldName = (String)args.get("field.name");
        try
        {
        	// get CustomField from FieldManager
        	fieldManager = ManagerFactory.getFieldManager();
        	CustomField cf = fieldManager.getCustomField(fieldName);
       		// Obtain the FieldLayoutItem associated with the custom field for this issue
		FieldLayoutItem fieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(cf);

        	// get the type of CustomField
        	String cfType = cf.getCustomFieldType().getKey();

        	if (cfType.equals("com.atlassian.jira.plugin.system.customfieldtypes:datetime") ||
            	cfType.equals("com.atlassian.jira.plugin.system.customfieldtypes:datepicker")	)
                {
            	  cf.updateValue(fieldLayoutItem, issue,UtilDateTime.nowTimestamp());
            	  issue.store();
                }
        	else
        	{
        	  cf.updateValue(fieldLayoutItem, issue,UtilDateTime.nowTimestamp().toLocaleString());
            	  issue.store();
        	}
        }
        catch
        (Exception e)
        {
        	 log.error("Exception: " + e, e);
        }
	}
}

Labels

workflow workflow Delete
plugin plugin Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Mar 22, 2006

    Benjamin Joguet says:

    Is there a version of this Extension working with Jira 3.5.2 ?

    Is there a version of this Extension working with Jira 3.5.2 ?

    1. Mar 26, 2006

      Nick Menere says:

      Hi, I just modified the code to use the FieldLayoutItem. More details on how to ...

      Hi,
      I just modified the code to use the FieldLayoutItem.
      More details on how to workwith custom fields, please refer to Working with Custom Fields.

      cheers,
      Nick

  2. Jul 13, 2006

    Sam Craig says:

    I was having trouble getting the above working in 3.6.2, so here is a modified v...

    I was having trouble getting the above working in 3.6.2, so here is a modified version of above which works with 3.6.2

     public class StoreExecutionTimeFunction implements FunctionProvider
    {
    	private FieldManager fieldManager;
    
    	private static final Category log = Category.getInstance(StoreExecutionTimeFunction.class);
    
    	public void execute(Map transientVars, Map args, PropertySet ps)
    	{
    		MutableIssue issue = (MutableIssue) transientVars.get("issue");
    		String fieldKey = (String) args.get("FieldName");
    
    		Field field = ManagerFactory.getFieldManager().getField(fieldKey);
    
    		FieldManager fldManager = ManagerFactory.getFieldManager();
    
    		try{
    			if (fldManager.isCustomField(field))
    			{
    				CustomField customField = (CustomField) field;
    				issue.setCustomFieldValue(customField, UtilDateTime.nowTimestamp());
    			} else {
    				GenericValue gvIssue = issue.getGenericValue();
    				gvIssue.set(fieldKey, UtilDateTime.nowTimestamp().toLocaleString());
    			}//end if
    		}catch(Exception cce){
    			log.error("Source Field Key: " + fieldKey);
    			log.error(cce);
    		}//end Try
    	}//end execute
    }//end class 
    1. Jul 13, 2006

      Sam Craig says:

      I should note that i have only tested this with Date picker custom fields, but i...

      I should note that i have only tested this with Date picker custom fields, but it should work for date time and string.

  3. Oct 25, 2006

    Dawn Hunter says:

    I'm embarrassed to ask, but where does this text need to go to enact this extens...

    I'm embarrassed to ask, but where does this text need to go to enact this extension? Do I just save it as an .xml file and put it in WEB-INF\classes (or WEB-INF\lib) ?

    1. Oct 29, 2006

      Nick Menere says:

      Dawn, Unless you were a Java developer you most probably wouldn't know this one...

      Dawn,

      Unless you were a Java developer you most probably wouldn't know this one.

      This code needs to go into .java file and then compiled and packaged. A good starting point for plugin development is our plugin guide, though it can be a little confusing for non java programmers.

      Cheers,
      Nick

  4. Mar 07, 2008

    Payal Agarwal says:

    This is a Java File . But the JIra plugin to be successful needs an atlassian pl...

    This is a Java File . But the JIra plugin to be successful needs an atlassian plugin .xml as well as a Factory . I was wondering if you have them for this particular class so I can just put all of them together and make a jar . It will be a big help .

    Thanks and Regards

    Payal