Custom Commands
The custom command can be used for performing custom operations with requests or operations with external systems. The custom command can be run for exactly one selected request. After its displaying to the user and its execution you can define conditions checking e.g. request status or value of its property.
The command can perform a sequence of actions within the ALVAO Service Desk, e.g. open the URL in the user default browser.
You have to have enabled the Custom program extensions to use the custom command.
Warning: The ALVAO database can be permanently damaged by the wrong definition of the custom command, therefore always perform the creation and testing on a copy of the database in the test environment.
Creating new command
In the folder with the ALVAO Service Desk WebService installed in the App_Code directory open the CustomCommands.cs file.
Into the bordered code block enter a definition of the new command by the ICommand interface implementation and set the values for id, name, and position properties in the command class constructor.
- id – command number (unique)
- name – command name displayed in the applications
- position – position 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:
… class Command1 : ICommand { CommandDesc commandDesc;
public CommandDesc CommandDesc { get { return commandDesc; } set { commandDesc = value; } }
public Command1() { int id = 1; string name = "Calculate total estimated work"; int position = 1;
commandDesc = new CommandDesc(id, name, position); } } …
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.
Example:
… class Command1: ICommand { … public bool Show(SqlConnection Con, int ticketId, int personId) { bool show = false;
// loading the required data about request from the database SqlCommand Cmd; 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;
SqlDataReader ticketReader = Cmd.ExecuteReader();
int sectionId; // id of a service where the request is string state; // request status int solverId; // request solver id
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 Solution status, the solver is the user who the request should be displayed to, or not if (sectionId == 1 && state == "Solution" && solverId == personId) show = true;
return show; }
// only 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).
Output is a truth value of the performance success, a text which can be displayed in the message for user and URL to open in a browser.
Example:
… class Command1: 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); } } … } …
Did not find what you were looking for? Ask our technical support team.
|