Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Automate complete state of Story from Post Release Validation after 14 working days

pampapathi1
Tera Expert

Hi All,

 

I have a requirement "Automate complete state of Story from Post Release Validation after 14 working days(complete and post release validation are the choice fields of the state).

I have created a scheduled job script below.

if (current.state == '-11') {
// Get the current date
var currentDate = new GlideDateTime();

// Calculate the date 14 working days from now
var targetDate = calculateTargetDate(currentDate);

// Check if the current date is equal to or greater than the target date
if (currentDate >= targetDate) {
// Update the state of the story to the desired state
// current.state = 'complete'; // Replace 'desired_state' with the state you want to move the story to//updated by pampa
current.state = '3';
current.update();
}
}

// Function to calculate the target date 14 working days from the given date
function calculateTargetDate(date) {
var workingDaysToAdd = 14; // Number of working days to add
var daysAdded = 0;

// Loop until working days added equals workingDaysToAdd
while (daysAdded < workingDaysToAdd) {
// Add one day to the date
date.addDays(1);

// Check if the added day is a working day (Monday to Friday)
if (date.getUTCDay() >= 1 && date.getUTCDay() <= 5) {
daysAdded++;
}
}

return date;
}

 

The above script is not working.

Could you please help on this.

 

Thanks,

Pampa

 

1 REPLY 1

pampapathi1
Tera Expert

Could you please suggest me on above issue.

 

Thanks,

Pampa