Skip Navigation LinksALVAO 10.1ALVAO Service DeskSystem Implementation in an OrganizationCustom Edits and ExtensionsCustom Program ExtensionsPeriodic custom actions Skip Navigation Links. Skip Navigation Links Skip Navigation Links.


Periodic custom actions

Custom actions can be executed at regular time intervals. The system executes periodic custom actions every hour.

For automatic actions to work you have to enable the Custom program extensions.

Warning:
The ALVAO database can be permanently damaged if a custom action is defined incorrectly; therefore, always use testing environment (e.g. a copy of the production database) to create and test actions.
Tip:
Creation of a working automatic action requires good knowledge of the ALVAO database and the Service Desk WebService interface.

Preparation of a new periodic action

In the folder where ALVAO Service Desk WebService is installed, copy the CodeExtension_Template.cs file in the App_Code folder and rename it according to the functionality performed by the action.

In the newly created file, enter a definition of the new custom action in a delimited code block by implementing the IPeriodicAction interface. Set the value for the Name property (the name of the custom action) in the action class's constructor.

Example

Solved requests are checked to find out whether or not their time limit for reopening by the requester (days) has elapsed and whether or not the automatic transition to the Closed status is disabled. If the requests are not closed within 14 days, they will be closed automatically.

1st part of the example:


class AutoCloseInactiveTickets : IPeriodicAction
{
    public string Name { get; set;}

    public AutoCloseInactiveTickets()
    {
        Name = "Automatic closing of resolved requests after the time limit for reopening by requester expires";
    }
}

Defining the conditions and executed operations for a periodic action

In the action's class you have created, implement the IPeriodicAction interface and its method OnPeriod.

In the implemented method, define both the conditions for executing the operations and the operations themselves.

2nd part of the example:


class AutoCloseInactiveTickets : IPeriodicAction
{

   public void OnPeriod(SqlConnection con)
   {
       try
       {
           string sql = @"
           if object_id('tempdb..#list') is not null
             drop table #list
           create table #list (id int primary key clustered, done bit default 0)

           -- obtaining all resolved requests whose time limit (days) for reopening by requester has expired and for which automatic transition to the Closed status is disabled
           insert #list (id)
           select
             t.iHdTicketId
           from tHdTicket t
             left join tHdSection s on s.iHdSectionId=t.liHdTicketHdSectionId
             join TicketState ts on ts.TicketStateBehaviorId=3 AND ts.TicketTypeId=s.TicketTypeId
           where t.dHdTicketResolved is not null
             and t.dHdTicketRemoved is null
             and ClosedDate is null
             and dateadd(day, isnull(s.nHdSectionUserReopenDays, 0), t.dHdTicketResolved)<getutcdate()

           -- signing in the log and closing requests
           declare @id int, @spid int
           select @spid=iPersonId from tPerson where bPersonSystem=1
           while(exists(select 1 from #list where done=0))
           begin
             select top 1 @id=id from #list where done=0

             insert tAct (liActHdTicketId,liActFromPersonId,liActKindId,CreatedByPersonId,dAct,sAct,mActNotice,bNoCharge,bWaitingForUser,dRecordCreated)
             select @id,@spid,9,@spid,getutcdate(),N'Automatic request closing',N'The request has been automatically closed',0,0,getutcdate()

             exec spCloseHdTicket @id,@spid,1
             update #list set done=1 where id=@id
           end
           select id from #list
           truncate table #list
           drop table #list
           ";
           using (SqlCommand cmd = new SqlCommand(sql, con, null))
           {
               Global.Person SystemPerson = Global.Person.GetSystem(con, null);
               using (SqlDataReader reader = cmd.ExecuteReader())
               {
                   // launching actions based on changed request status
                   HelpdeskWebService sdws = new HelpdeskWebService();
                   while (reader.Read())
                   {
                       int id = Int32.Parse(reader["id"].ToString());

                       try
                       {
                           sdws.OnTicketChanged(id, SystemPerson.Id, "tHdTicket.sHdTicketStateNotice");
                       }
                       catch (Exception)
                       {
                           //Exception is ignored
                       }
                   }
                   reader.Close();
               }
           }
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }

}

The whole example can be downloaded here.

 

Did not find what you were looking for? Ask our technical support team.