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 ?
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)
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)
Thank you @David Fischer for quick response, it's working good.
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.