Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,368,233
Community Members
 
Community Events
168
Community Groups

ScriptRunner postfunction to clear custom field doesn't work in create transition

I have the same postfunction that I attach to every transition in a workflow that checks what status the transition is going into and manipulates a couple of Date Picker custom fields depending on which status.  It works great for all of the transitions EXCEPT for the create one.  Essentially we have a status for when a design change is complete and it's ready to get verified (RdyToVerify) and one when the verification of that design change is complete (Verified) and upon entry into those statuses we set a custom field recording when that occurred (RTL Resolved Date , DV Resolved Date resp.). 

If someone clones a bug that has the values set it will activate the code on the create transition (I see the log messages telling me like "now going into New status" so I know it's running) but it refuses to set or clear the custom field values in that transition.  The same if I set the values in the create screen and hit create, it wont change the custom field values. (my logic is that in those states of "New" or "In Progress" those should be cleared so my code attempts to clear them).  The setting to null works great when i transition OUT of New and into In Progress but it just refuses to work on the transition INTO the New state as part of the create transition.  I've also tried moving it to every position in the list of postfunctions.

 

Code is below : 

 

 

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.fields.CustomField

import java.sql.Timestamp

 

// enable logging so we can see 'info' type and not just 'error'

import org.apache.log4j.Logger

import org.apache.log4j.Level

log.setLevel(Level.INFO)

 

 

 

 

 

def customFieldManager = ComponentAccessor.getCustomFieldManager()

 

def the_status = issue.getStatusObject().getName()

log.info("The status is "+the_status)

 

 

// RTL

def RTL_Date_Object  = customFieldManager.getCustomFieldObjectByName("RTL Resolved Date")

def RTL_Date_Value   = issue.getCustomFieldValue(RTL_Date_Object)

 

//DV

def DV_Date_Object   = customFieldManager.getCustomFieldObjectByName("DV Resolved Date")

def DV_Date_Value    = issue.getCustomFieldValue(DV_Date_Object)

 

// get today's date

def today = new java.sql.Timestamp(new Date().getTime())

 

// clear it if you're going to an early status, up to In Progress

if (the_status == "New" || the_status == "In Progress") {

    if (RTL_Date_Value) {

       issue.setCustomFieldValue(RTL_Date_Object, null)

    }

    if (DV_Date_Value) {

        issue.setCustomFieldValue(DV_Date_Object, null)

    }

}

 

// entering RdyToVerify, set the RTL resolved and clear the DV resolved

if (the_status == "RdyToVerify") {

    if (! RTL_Date_Value) {

       issue.setCustomFieldValue(RTL_Date_Object, today)

    }

    if (DV_Date_Value) {

        issue.setCustomFieldValue(DV_Date_Object, null)

    }

}

 

// set both if you're in a late status, Verified or after

if (the_status == "Verified" || the_status == "Closed") {

    if (! RTL_Date_Value) {

       issue.setCustomFieldValue(RTL_Date_Object, today)

    }

    if (! DV_Date_Value) {

        issue.setCustomFieldValue(DV_Date_Object, today)

    }

}

 

 

1 answer

Hey there Matthew, just wanna confirm and cover our bases, was this script added into the post-function of the 'Create' transition as well? 

yes and i put it in every position .. 1st, 2nd, etc

the same code works once it's created and I move from "New" to "In Progress" so I know the code works, it just doesnt seem to be effective in the create.  Again I can see the log messages of it running in create like "The status is New" but no ability to clear those fields

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events