Skip Navigation LinksALVAO 10.0ALVAO Service DeskSystem Implementation in an OrganizationCustom Edits and ExtensionsCustom Program ExtensionsAutomatic Actions Triggered by Event on Request Skip Navigation Links. Skip Navigation Links Skip Navigation Links.


Automatic Actions Triggered by Event on Request

Automatic actions can be started in the following cases:

  • Request item value change (custom/system)
  • Creating a new request
  • Creating a new event
  • Editing an event
  • Deleting an event

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

Warning:
The ALVAO database can be permanently damaged if an automatic action is defined incorrectly; therefore, always use a copy of the database in the test environment to perform creation and testing.
Tip:
Creation of a working automatic action requires good knowledge of the ALVAO database and the Service Desk WebService interface.

Preparation of new automatic 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 automatic action into the bordered code block by implementing the ITicketAutoAction or IActAutoAction interface and set the value for the name property (name of the automatic action) in the command class constructor.

Example:


class TicketAutoAction1: ITicketAutoAction
{
    public string name;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }

    public TicketAutoAction1()
    {
        name = "Resolved in Version – Assign to test";
    }
}

Defining the conditions and executed operations for automatic action

Warning:
If you only want to use some of the methods of the implemented interface within the automatic action, return the NotImplementedException exception in the body of other methods of the interface. E.g. as follows:

public void OnTicketChanged(SqlConnection con, SqlTransaction trans, int ticketId, int personId, string properties)
{
    throw new NotImplementedException();
}

Actions performed when the request item is changed

Automatic actions can be executed when the following items are changed:

table.column Request Item
tHdTicket.sHdTicketStateNotice Status
tHdTicket.liHdTicketSlaId SLA
tHdTicket.dHdTicketDeadline Due Date
tHdTicket.liHdTicketHdSectionId Service
tHdTicket.iHdTicketUser Requester
tHdTicket.liHdTicketSolverPersonId Solver
tHdTicket.sHdTicket Request name
tHdTicket.liHdTicketPriorityId Priority
tHdTicket.Impact Impact
tHdTicket.Urgency Urgency
tHdTicket.mHdTicketNotice Notes
tHdTicket.sHdTicketCategory Category
tHdTicket.sHdTicketGroup Group
tHdTicket.dHdTicketUserDeadline Requested due date
tHdTicket.sHdTicketDeviceCode Device number
tHdTicket.liHdTicketNodeId Device
tHdTicket.sHdTicketHdBranch Area
tHdTicket.FeedbackSolveSpeed Resolution speed
tHdTicket.FeedbackProfessionality Professionalism
tHdTicket.FeedbackExpertise Expertise
tHdTicket.FeedbackComment Comments and notes
tHdTicket.RelatedAccountId Related organizations
tHdTicketCust.* Custom Items

In the created action class, implement the ITicketAutoAction interface and its method OnTicketChanged. The input parameters are the following:

  • ticketId (request number)
  • personId (id of the person who performed the event on the request) – In some cases, it might have been the system, if so, the value is NULL
  • properties (changed request items separated by comma – table.column)

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

Example:


class TicketAutoAction1: ITicketAutoAction
{

    public void OnTicketChanged(SqlConnection con, SqlTransaction trans, int ticketId, int personId, string properties)
    {
        if (properties.Contains("tHdTicketCust.solvedInVersion"))
        {
            try
            {
                HelpdeskWebService sdws = new HelpdeskWebService();

                // loading values
                string solvedInVersion = sdws.ReadColumn(ticketId, "tHdTicketCust", "solvedInVersion");
                string section = sdws.ReadColumn(ticketId, "TicketForeignKeyInfo", "SectionName");
                string state = sdws.ReadColumn(ticketId, "tHdTicket", "sHdTicketStateNotice");

                // checking values
                if (!String.IsNullOrEmpty(solvedInVersion) && section == "Program edits"&& state == "Implementation")
                {
                    // loading data
                    SqlCommand Cmd;
                    Cmd = new SqlCommand(@"SELECT TOP 1 TRP.liRolePersonPersonId newSolverId FROM tRolePerson TRP JOIN tRole TR ON TRP.liRolePersonRoleId=TR.iRoleId WHERE TR.sRole = N'Testers'", con, trans);
                    SqlDataReader reader = Cmd.ExecuteReader();

                    int newSolverId; // new request solver id

                    if (reader.Read())
                    {
                        newSolverId = int.Parse((reader["newSolverId"]).ToString());

                        // assigning to solver
                        sdws.AssignToSolver(ticketId, newSolverId);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

}

Actions performed when a new request is created

In the created automatic action class, implement the ITicketAutoAction interface and its method OnTicketCreated. The input parameters are the following:

  • ticketId (request number)
  • personId (id of the person who created the request – sometimes can be other than the requester).

Example:


class TicketAutoAction1: ITicketAutoAction
{

    public void OnTicketCreated(SqlConnection con, SqlTransaction trans, int ticketId, int personId)
    {
        try
        {
            HelpdeskWebService sdws = new HelpdeskWebService();

            // loading values
            bool createAnalysis = bool.Parse(sdws.ReadColumn(ticketId, "tHdTicketCust", "createAnalysis"));
            string section = sdws.ReadColumn(ticketId, "TicketForeignKeyInfo", "SectionName");
            string name = sdws.ReadColumn(ticketId, "tHdTicket", "sHdTicket");

            // checking values
            if (section == "Program edits"&& createAnalysis)
            {
                // creating the request for proposal creation
                int newTicket = sdws.CreateTicket(personId, personId, null, null, "Development\\Program edits\\Proposals and Analyses", null, name + " - proposal", null, null, null, null, null,
                                                   DateTime.Now.ToUniversalTime(), 7);

                // creating the link
                SqlCommand Cmd;

                Cmd = new SqlCommand(@"INSERT INTO TicketRelation (BeginHdTicketId, EndHdTicketId, TicketRelationTypeId) VALUES (@rootTicket, @newTicket, 2)", con, trans);
                Cmd.Parameters.Add("@rootTicket", SqlDbType.Int).Value = ticketId;
                Cmd.Parameters.Add("@newTicket", SqlDbType.Int).Value = newTicket;
                Cmd.ExecuteNonQuery();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

}

Actions performed when an event is created

Automatic actions can be executed in the following situations:
  • Manual creation of any event using the New event or New note command in the SD Console or WebApp.
  • Sending a message using the commands Send message, Reply, etc. in the SD Console or WebApp.
  • Loading an e-mail from the service mailbox using MailboxReader.
  • Loading a message manually using the Load messages from MS Outlook command in the SD Console.
  • Loading a message manually using the Save to request log in Outlook Add-in.
  • Creating a creation event for a new request.
  • By calling the web method CreateAct or CreateTicket, where the creating message is created.

In the created automatic action class, implement the IActAutoAction interface and its method OnActCreated. The input parameters are the following:

  • actId (event id),
  • personId (id of the person who created the event).

Example:

When an event is created in the Program edits service, the event is sent via e-mail to all managers on the service who are not authors or recipients of the event.
class ActAutoAction1IActAutoAction {     …     public void OnActCreated(SqlConnection con, SqlTransaction trans, int actId, int personId)     {                     try         {             HelpdeskWebService sdws = new HelpdeskWebService();               // loading values             int ticketId = 0, fromPersonId = 0;             string actTo = "", actToEmail = "", actSubject = "", actPlainText = "";             using(SqlCommand Cmd = new SqlCommand(@"SELECT liActHdTicketId, liActFromPersonId, sActTo, sActToEmail, sAct, mActNotice FROM tAct WHERE iActId = @actId", con, trans))             {                 Cmd.Parameters.Add("@actId"SqlDbType.Int).Value = actId;                 using(SqlDataReader reader = Cmd.ExecuteReader())                 {                     if (reader.Read())                     {                         ticketId = int.Parse((reader["liActHdTicketId"]).ToString());                         fromPersonId = int.Parse((reader["liActFromPersonId"]).ToString());                         actTo = (reader["sActTo"]).ToString();                         actToEmail = (reader["sActToEmail"]).ToString();                         actSubject = (reader["sAct"]).ToString();                         actPlainText = "Hello,\n\n an event has been created on request number " + ticketId.ToString() + ":\n\n" + (reader["mActNotice"]).ToString();                     }                 }             }             string sectionName = sdws.ReadColumn(ticketId, "TicketForeignKeyInfo""SectionName");                              // checking values             if ((sectionName == "Program edits"&& (fromPersonId != personId))             {                 // loading data                 sectionId = int.Parse(sdws.ReadColumn(ticketId, "tHdTicket""liHdTicketHdSectionId"));                 string sectionEmail = sdws.ReadColumn(sectionId, "tHdSection""sHdSectionEmail");                                      List<string> recipients = new List<string>();                 string sectionId = sdws.ReadColumn(ticketId, "tHdTicket""liHdTicketHdSectionId");                 using (SqlCommand Cmd = new SqlCommand(@"select sPersonEmail from vHdSectionManager                                                          left join tPerson on iPersonId = liHdSectionManagerPersonId                                                          where sPersonEmail is not null liHdSectionManagerHdSectionId = @sectionId", con, trans))                 {                     Cmd.Parameters.Add("@sectionId"SqlDbType.Int).Value = sectionId;                     using (SqlDataReader reader = Cmd.ExecuteReader())                     {                         string personEmail = (reader["sPersonEmail"]).ToString();                         if(!actTo.Contains(personEmail) && !actToEmail.Contains(personEmail))                             recipients.Add(personEmail);                     }                 }                   //sending e-mail                 if(recipients.Count > 0)                     sdws.SendMail(ticketId, sectionEmail, recipients, null, actSubject, actPlainText, falsefalse, con, trans);             }         }         catch (Exception ex)         {             throw ex;         }     }     … } …

Actions performed when an event is edited

Automatic actions can be executed when the following items are changed:

table.column Event item
tAct.dAct Date
tAct.liActKindId To
tAct.sActTo Date
tAct.sAct Subject
tAct.mActNotice Text
tDocument.liDocumentActId Attachments
tActHd.bActHdUserRead Show to requester
tAct.bWaitingForUser Waiting for requester
tAct.nActWorkHours Work
tAct.nActTravelHours Time spent on trip
tAct.nActTravelKm Distance
tAct.bNoCharge Do not invoice

In the created automatic action class, implement the IActAutoAction interface and its method OnActChanged. The input parameters are the following:

  • actId (event id),
  • personId (id of the person who changed the event),
  • properties (changed event items separated by commas – table.column).

Actions performed when an event is deleted

Automatic actions can be executed when deleting all messages and events.

In the created automatic action class, implement the IActAutoAction interface and its method OnActRemoved. The input parameters are the following:

  • actId (event id),
  • personId (id of the person who deleted the event).

Sending a message within the automatic action

If you need to send any message within the automatic action, use the SendMail method with the parameters described below. The message sent can also be written into the request log automatically.

Description of parameters of the SendMail method.

Parameter Data Type Description Required
ticketId int Request ID for which the record will be created. Yes
from string Sender e-mail. If not filled in, the sender is the service. No
recipients string[] Field for message recipients. Yes
cc string[] Field for message copy recipients. No
subject string Subject of the message. If not filled in, the request tag and name will be used. No
body string Message (can be in the HTML format). Yes
createAct bool Create event in the request log. Yes
notification bool The event created in the request log will have the Notification kind. Yes
connection SqlConnection Database connection. Yes
transaction SqlTransaction Database transaction in progress. No
Note:
The method can be used also for the custom commands.
Tip:
You can use the following function to compose the HTML message: string HtmlNotificationBody(string htmlBody) which envelopes the htmlBody with standard envelope.
Tip:
The whole e-mail can be also composed individually using the MailMessage object and then using the overloaded method:
public int SendMail(MailMessage msg, int ticketId, bool createAct, bool notification, SqlConnection connection, SqlTransaction transaction);
In this way, you can send a message with attachments and images within text eventually.

Release value

  • ID of the created event if the e-mail has been sent successfully and the event has been created.
  • 0 if the e-mail has been sent successfully, but the event has not been created.
  • -1 if the e-mail has not been sent, e.g. due to incorrectly set SMTP server.
  • Any exception, as they aren't detected or processed in the method body.

 

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