Skip Navigation LinksALVAO 10.1ALVAO Service DeskSystem Implementation in an OrganizationCustom Edits and ExtensionsCustom Program ExtensionsCustom CommandsCustom Request Commands Skip Navigation Links. Skip Navigation Links Skip Navigation Links.


Custom Request Commands

Creating a new command

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 of the custom command.

In the newly created file, enter a definition of the new command into the bordered code block by implementing the ICommand interface and set the values for the id, name, and position properties in the command class constructor.

  • id – command number (unique)
  • name – command name displayed in the applications
  • position – position at which the command will be displayed in the applications
    • 1 = on the first place of the request main menu
    • 2 = on the last place of the request main menu
    • 3 = on the first place of a menu nested in the request main menu
    • 4 = on the last place of a menu nested in the request main menu

Example

The command will summarize the values of the SW costs and HW costs custom items of the request.

1st part of the example:


class CostCalculation : ICommand
{
    CommandDesc commandDesc;

    public CommandDesc CommandDesc
    {
        get { return commandDesc; }
        set { commandDesc = value; }
    }

    public CostCalculation()
    {
        int id = 1;
        string name = "Calculate total SW and HW costs";
        int position = 1;

        commandDesc = new CommandDesc(id, name, position);
    }

    int controlSectionId = 1; // ID of the service in which the request should be for the option to be displayed
    string stateName = "Solution"; // The name of the request status required for the option to be displayed
}

Defining conditions for displaying the command

In the created command class, implement the Show method from the ICommand interface. Input parameters are ticketId (request number) and personId (id of a person who should see the command).

Output is then a truth value representing whether the command should display to the user on the entered request, or not.

Tip:
By calling this method in the Run(…) method you can check before running the query, whether the conditions for its displaying changed in the period between displaying and running the query, or not.

2nd part of the example:


class CostCalculation : ICommand
{
    …
    public bool Show(SqlConnection Con, int ticketId, int personId)
    {
        bool show = false;

        int sectionId; // id of the service where the request is located
        string state; // request status
        int solverId; // request solver id

        // loading the necessary request data from the database
        using (SqlCommand cmd = new SqlCommand(@"SELECT liHdTicketHdSectionId, sHdTicketStateNotice, liHdTicketSolverPersonId FROM tHdTicket
        WHERE liHdTicketSolverPersonId IS NOT NULL AND iHdTicketId = @iHdticketId", Con))
        {
            cmd.Parameters.Add("@iHdTicketId", SqlDbType.Int).Value = ticketId;
            using (SqlDataReader ticketReader = cmd.ExecuteReader())
            {
                if (ticketReader.Read())
                {
                    sectionId = int.Parse((ticketReader["liHdTicketHdSectionId"]).ToString());
                    state = (ticketReader["sHdTicketStateNotice"]).ToString();
                    solverId = int.Parse((ticketReader["liHdTicketSolverPersonId"]).ToString());
                    ticketReader.Close();
                }
                else
                {
                    ticketReader.Close();
                    return show;
                }
            }
        }

        // checking whether the request is in the requested service, in the Resolution status, and the solver is the user who the request should be displayed to, or not
        if (sectionId == controlSectionId && state == stateName && solverId == personId)
            show = true;

        return show;
    }

    // just copy this part of the code
    public List<Tuple<int, bool>> Show(SqlConnection Con, List<int> ticketsIds, int personId)
    {
        throw new NotImplementedException();
    }

}

Defining actions performed by the command

In the created command class, implement the Run method from the ICommand interface. Input parameters are ticketId (request number) and personId (id of a person who is running the command).

The output is a truth value based on the success of execution, a text which can be displayed in the message for the user, and a URL to open in a browser.

3rd part of the example:


class CostCalculation : ICommand
{

    public Tuple<bool, string, string> Run(SqlConnection Con, int ticketId, int personId)
    {
        bool complete = false;
        string message = "";
        string url = "";

        // Check, whether the conditions for running/displaying the command changed in the period between displaying and running it, or not (can be performed anywhere in this Run method).

        if (!Show(Con, ticketId, personId))
        {
            message = "Command can not be performed as the conditions for its displaying has not been met.";
            complete = false;
            return Tuple.Create(complete, message, url);
        }

        complete = true;
        SqlTransaction transaction = Con.BeginTransaction();
        try
        {
            HelpdeskWebService sdws = new HelpdeskWebService();

            // loading values from the “SW costs” and “HW costs” custom items
            string strCostSW = sdws.ReadColumn(ticketId, "tHdTicketCust", "costSW");
            int costSW = string.IsNullOrEmpty(strCostSW) ? 0 : int.Parse(strCostSW);
            string strCostHW = sdws.ReadColumn(ticketId, "tHdTicketCust", "costHW");
            int costHW = string.IsNullOrEmpty(strCostHW) ? 0 : int.Parse(strCostHW);
            int costTotal = costSW + costHW;

            // writing the sum of costSW and costHW into the Total costs custom item
            sdws.WriteColumn(ticketId, "tHdTicketCust", "costTotal", costTotal.ToString());

            transaction.Commit();

            return Tuple.Create(complete, message, url);
        }
        catch (Exception ex)
        {
            message = "Error when writing the value.";
            complete = false;
            url = "";
            transaction.Rollback();
            return Tuple.Create(complete, message, url);
        }
    }

}

The whole example can be downloaded here.

To run the example, you must add the costSW, costHW, and costTotal custom items of the int type to the tHdTicketCust table.

Tip:
If the custom command should open another page from ALVAO WebApp, use the GetServiceDeskPortalUrl() method from the Service Desk WebService interface to find the root URL of WebApp. E.g.:
string waUrl = "";
using(HelpdeskWebService ws = new HelpdeskWebService())
{
    waUrl = ws.GetServiceDeskPortalUrl();
}
if (waUrl.Length == 0)
    throw new Exception("WebApp address not set.");

 

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