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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Post function script to update due date only if its empty

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

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
}

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

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

It worked. Thanks Nic.

Suggest an answer

Log in or Sign up to answer
TAGS

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