Hi,
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 = LocalDateTime.now().withHour(22).withMinute(00) def hour = LocalDateTime.now().getHour() LocalDateTime horaLimite20 = LocalDateTime.now().withHour(20).withMinute(00) LocalDateTime horaLimite14hoy = LocalDateTime.now().withHour(14).withMinute(00) LocalDateTime horaLimite14manana = LocalDateTime.now().withHour(14).withMinute(00).plusDays(1) 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) ) else 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) ) else 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
Community moderators have prevented the ability to post new answers.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Agree with Nic... but do yourself a favour and use braces, ie if () { ... }
It's too easy to make a mistake otherwise.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.