Post function script to update due date only if its empty

rohit sharma November 11, 2020

Hi All,

I have written a post function script to read the data form the linked ticket and then add the required data in to the current ticket. So, there is a need to update the due date of the current ticket form linked issue only if the due date of the current ticket is empty. I have written a block to check if the due date is null or not but this block is failing 

if - will run if the due date is null or empty

else- will run if the due date is not empty

I have set the logs , the logs are saying the value of due Date is null but still the code is not triggering the if block

if(String_dueDate.isEmpty() == true || String_dueDate == null ||String_dueDate.length() == 0)
{
log.debug("In If And Parent Due is "+ issue2.getDueDate())
log.debug("Current Due is"+ issue1.getDueDate() )
issue1.setDueDate(due_Date_2_value);
}
else
{
log.debug("In Else And Parent Due is "+ issue2.getDueDate())
log.debug("Current Due is"+ issue1.getDueDate() )
}

I don't under stand what's wrong in the code. 

I have converted the due date outcome to string as well and then I am comparing

def due_Date_1_value = issue1.getDueDate()
String String_dueDate = due_Date_1_value.toString()

Please help me to understand and fix this.

 

Thanks,

Rohit

 

 

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2020

There is no need to mess about converting to strings to do this comparison, and in fact, this is making it worse for you because you're comparing things that you've cast and not fully understood the results of the cast.

The most simple structure you could use here is:

def due_Date_1_value = issue1.getDueDate()

if ( due_Date_1_value )
{
// due date is filled, do nothing
}
else
{
// due date is empty, do stuff
}
rohit sharma November 11, 2020

Thanks NIC for your answer. Before updating the due date in the ticket I need to first check whether the due date for the ticket already updated. If it's empty then only update the due date.

That's the only reason for if and else clause.

 

Regards,

Rohit

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2020

I know that, that's why I gave you the code to do that.

rohit sharma November 18, 2020

It worked. Thanks Nic.

Suggest an answer

Log in or Sign up to answer