Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Skip the post function when the field doesn't have value while creating the ticket

Lakshmi CH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 30, 2020

Hi Team,


We have date type custom field "Need By Date", and we have another field "CS Sold Date" on create screen. "Need By Date" has already below script based on ticket created date + 3 days. If we enter the date in the "CS Sold Date" while creating the ticket, The "Need By Date" should recalculate based on  "CS Sold Date"+ 3 days (Need by date already +3 days on created date).  I have added other post function for Need By Date with same script, replacing date(issue.get("CS Sold Date"),3) with date (new Date(),3). It is working good if I give the CS Sold Date field value, not working if I am not giving the CS Sold Date while creating the ticket. I am sure that obviously the both post functions work one by one, and when it comes to 2 nd post function, it will look for CS Sold Date to update the Need By Date to 3 days. Could you please suggest how to skip the post function if we did not give the value of  CS Sold Date ?

 

new date error.PNG

The code is

 

Date date(Date from, int nod){
    Calendar c1 = GregorianCalendar.getInstance();
    c1.setTime(from);
 
    int weeks = nod/5;
    int remDays = nod%5;
 
    //Adding whole weeks
    c1.add(Calendar.WEEK_OF_YEAR, weeks);
 
    //Run a loop and check each day to skip a weekend
    for(int i=1;i<=remDays;i++){
      c1.add(Calendar.DAY_OF_MONTH, 1);
    if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
        c1.add(Calendar.DAY_OF_MONTH, 1);
    if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
        c1.add(Calendar.DAY_OF_MONTH, 1);
        }
 
    //Skip ending weekend
    if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
        c1.add(Calendar.DAY_OF_MONTH, 1);
    if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
        c1.add(Calendar.DAY_OF_MONTH, 1);
    
 
    //move to 0:00
    c1.clearTime();
     
    return c1.getTime();
}
date(issue.get("duedate"),5)

 

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
July 30, 2020

You don't actually need two post functions, one is enough. Replace the last line with:

date(issue.get("CS Sold Date") ?: new Date(), 3)
Lakshmi CH
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2020

Thank you @David Fischer for quick response, it's working good.

Suggest an answer

Log in or Sign up to answer