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

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
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

688 views 7 23
Read article

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