Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


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
Community Members
Community Events
Community Groups

Custom field not update in post function


I am using Scriptrunner in a post function to set a value of a custom field, but it is not working. I have the post function the first in the list of post functions, but it still not working. There is my code:



import java.time.LocalDateTime
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.datetime.*
import org.joda.time.DateTime;
import java.time.ZoneId
import java.sql.Timestamp
import java.util.Calendar
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def textCf = customFieldManager.getCustomFieldObjectByName("Fecha Finalización SLA")
def tgtField = customFieldManager.getCustomFieldObjectByName("Móvil - Descripción Estado")
LocalDateTime defaultTime =
def hour =
LocalDateTime horaLimite20 =
LocalDateTime horaLimite14hoy =
LocalDateTime horaLimite14manana =
Date fechaDef = new DateTime(Date.from(defaultTime.atZone(ZoneId.systemDefault()).toInstant())).toDate()
Date fecha20 = new DateTime(Date.from(horaLimite20.atZone(ZoneId.systemDefault()).toInstant())).toDate()
Date fecha14 = new DateTime(Date.from(horaLimite14hoy.atZone(ZoneId.systemDefault()).toInstant())).toDate()
Date fecha14manana = new DateTime(Date.from(horaLimite14manana.atZone(ZoneId.systemDefault()).toInstant())).toDate()
MutableIssue issueToUpdate = (MutableIssue) issue;

if(tgtField.getValue(issue).toString().equalsIgnoreCase( "Grabación manual solicitud Siebel")) 
if(hour > 14 && hour < 20)
issueToUpdate.setCustomFieldValue(textCf,new Timestamp(fecha20.time) ) 

else if (hour >= 20 && hour <24)
issueToUpdate.setCustomFieldValue(textCf,new Timestamp(fecha14manana.time) )

issueToUpdate.setCustomFieldValue(textCf,new Timestamp(fecha14.time) ) 

else if(tgtField.getValue(issue).toString().equalsIgnoreCase( "Verificación manual estado provisión Siebel") ||
tgtField.getValue(issue).toString().equalsIgnoreCase( "Grabación manual pedido en SAP") )
if(hour > 14 && hour <=24)
issueToUpdate.setCustomFieldValue(textCf,new Timestamp(fecha14manana.time) )

issueToUpdate.setCustomFieldValue(textCf,new Timestamp(fecha14.time) )


But if i write the line: 

issueToUpdate.setCustomFieldValue(textCf,new Timestamp(fecha14.time))

before the ifs, it changes the value. So i think the problem is when the instruction is inside the if, but i dont get how to solve it 


Thanks in advance

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes

I'm not sure it's seeing "hour" as a simple number object.  Are you sure it contains a number (and that it's the right number)?

Yes, it is, there is no problem in the conditions of the If clauses. The flow goes ahead them correctly and enters in the right way.

The problems is the instruction:

issueToUpdate.setCustomFieldValue(textCf,new Timestamp(fecha14.time))

inside the clauses seems not doing anything, but the flow of the script goes through it, i checked it with logs

But you said it works outside the if statement?  Just being inside an "if" won't change what it does, which implies it's the "if" statement that isn't working.

Yes, it works outside.

That is what i ask here, because i tested that it enters inside the if, but the instruction don't work. The if statement is working correctly

Wrapping a line in an "if" block does not change the way the line works.

There is one nagging doubt, but it's hard to explain - what, exactly is the if/then/else block that is failing?

JamieA Rising Star Mar 28, 2017

Agree with Nic... but do yourself a favour and use braces, ie if () { ... }

It's too easy to make a mistake otherwise.

AUG Leaders

Atlassian Community Events