I’ve edited this post to work with current work periods
I’ll be reusing actions/rules from the following tutorial:
With the above tutorial, I did not see anywhere where the ticket number or ID is passed to any actions/rules.
The way around it is to manually enter the ticket number (visible on the top left of the ticket). There may be another way, but I know this one works.
Script:
Script Name: Reopen Check
Handler: reopen
function check(ticketid)
{
qtd = "SELECT FORMAT(Date, 'yyyy-MM-ddTHH:mm:ss') FROM Tickets WHERE Id = '"+ticketid+"'";
var rtd = sql.Exec(qtd)[0];
qwp = "SELECT FORMAT(StartDate, 'yyyy-MM-ddTHH:mm:ss') FROM WorkPeriods WHERE Id = (SELECT MAX(Id) FROM WorkPeriods WHERE StartDate = EndDate)";
var rwp = sql.Exec(qwp)[0];
if (rtd >= rwp)
{
return 1;
}
else
{
return 0;
}
}
Actions:
Action Name: Reopen - Load Ticket
Action Type: Load Ticket
Ticket Number: [:Ticket Number]
(if you don’t already have one)
Action Name: Execute Automation Command
Action Type: Execute Automation Command
Automation Command Name: [:Command Name]
Command Value: [:Command Value]
Action Name: MSG TEST
Action Type: Show Message
Message: [:Message]
Rules:
Rule Name: Reopen
Event Name: Automation Command Executed
Execute Rule if: [Matches]
Custom Constraint:
**Automation Command [Equals] Reopen
** or set this to the button you currently have visible on the ticket screen
Actions to Add:
Action: Reopen - Load Ticket
Constraint:
Ticket Number: [?Ticket Number;\d*;;OCN]
Action: Execute Automation Command
Constraint: {CALL:reopen.check(‘{TICKET ID}’)} == 1
Command Name: Reopen - Reopen Ticket
Command Value: {TICKET ID}
Action: MSG TEST
Constraint: {CALL:reopen.check(‘{TICKET ID}’)} == 0
Message: Ticket out-of-range\rUnable to reopen
Change the Custom Constraint for RU Reopen Settled Ticket:
Custom Constraint:
Automation Command Name [Equals] Reopen - Reopen Ticket
Reopening ticket from today:
Reopening ticket from not today:
EDIT: Updated script