Skip Navigation LinksALVAO 8.2ALVAO 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

You have to have enabled the Custom program extensions to allow the work of automatic actions.

Warning:
The ALVAO database can be permanently damaged by the wrong definition of the automatic action, therefore always perform the creation and testing on a copy of the database in the test environment.
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

Open the CustomAutoActions.cs file In the App_Code directory located in the ALVAO Service Desk WebService installation.

Into the bordered code block enter a definition of the new automatic action by the IAutoAction interface implementation and set the value for name property (automatic action name) in the action class constructor.

  • name – automatic action name

Example:


class AutoAction1 : IAutoAction
{
    public string name;

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

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

Defining the conditions and executed operations for automatic action

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 OnTicketChanged method from the IAutoAction interface. 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 AutoAction1: IAutoAction
{

    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 OnTicketCreated method from the IAutoAction interface. 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 AutoAction1: IAutoAction
{

    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 + " - návrh", 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;
        }
    }

}

Warning:
If you want to use only one of the methods above within the automatic action, return the NotImplementedException exception in the body of the second one. E.g. as follows:

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

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.