Imagine the situation where your colleague is on-call but he has an important, unplanned appointment. He calls you if you can cover him for two hours. Of course you can. Wouldn’t it be convenient now if you can just manage this easily from your mobile app? You can. You just need two things in Enterprise Alert:
- A Remote Action with the form to set you as stand-in
- The script that does the work for you in the background
Here we go ….
Remote Action
The Remote Action form allows you to set (or delete) yourself as a stand-in for a specific on-call team at a specific time.
You can add the Remote Action under “Remote Actions” -> “Remote Actions” -> “Create New” and then configure it in the following way.
General:
Action:
Under the Action you define to execute a script (see below). The mentioned parameters will be passed to the script as function arguments. In this example we provided a list of team names the user can choose from.
Script
The above Remote Action calls a script which does the processing on the database. For our example the script looks as follows.
/* This script writes values into a database table. Add;Delete 00:00;00:30;01:00;01:30;02:00;02:30;03:00;03:30;04:00;04:30;05:00;05:30;06:00;06:30;07:00;07:30;08:00;08:30;09:00;09:30;10:00;10:30;11:00;11:30;12:00;12:30;13:00;13:30;14:00;14:30;15:00;15:30;16:00;16:30;17:00;17:30;18:00;18:30;19:00;19:30;20:00;20:30;21:00;21:30;22:00;22:30;23:00;23:30 2017;2018;2019;2020 01;02;03;04;05;06;07;08;09;10;11;12 01;02;03;04;05;06;07;08;09;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;2;26;27;28;29;30;31 © 2017 Derdack GmbH, www.derdack.com Copyright 2016 - 2017 Derdack GmbH, www.derdack.com, Enterprise Alert is a registered trademark of Derdack GmbH Author: Hanno Ferdinand Versions: 16.03.2017 HF 1.0 Initial version */ var strVersion = "RA_SetStandIns 16.03.2017 v1.0 "; /* ============================================================================= CONFIGURATION ============================================================================= */ // Enterprise Alert database connection string var APPCONFIG_DB_EA_CONNECTIONSTRING = "Driver=SQL Server Native Client 10.0;Server=(local);Trusted_Connection=Yes;Database=MMEA"; //Testfunctions //EAScriptHost.LogDebug("Service2Ticket() :" + SetStandIn("Add", "hferdi","Database", "2017-03-20","12:00","13:00")); //EAScriptHost.LogDebug("Service2Ticket() :" + SetStandIn("Delete", "hferdi","Database", "2017-03-20","12:00","13:00")); EAScriptHost.LogInfo("Execute Remote action Startup " + strVersion); /* * Still to set * */ function SetStandIn(Modus,Teamname,TimeStart,TimeEnd,Year,Month,Day,Username) { //Modus Delete StandIn or Add StandIn //shortDate - Today, Tomorrow, After tomorrow //Time Start 00:00 00:30 01:00 var oConnInternalDB = null; var bInTransInternalDB = false; var oExec = 1; var allOut = ""; var allError = ""; try { // Open the db connection // oConnInternalDB = new ActiveXObject("ADODB.Connection"); oConnInternalDB.IsolationLevel = 1048576; // Set the isolation level // to // Serializable oConnInternalDB.Open(APPCONFIG_DB_EA_CONNECTIONSTRING); EAScriptHost.LogDebug("Db Internal Connection Opened"); oConnInternalDB.BeginTrans(); //find Team and PlanUserID //SELECT [TeamOnCallPlans].[OnCallPlanID], [OnCallPlanUsers].[ID], [OnCallPlanUsers].[ProfileDisplayName], MMPROFILES.PROFNAME //FROM [TeamOnCallPlans],[OnCallPlanUsers], MMPROFILES where [TeamOnCallPlans].[OnCallPlanID] = [OnCallPlanUsers].[OnCallPlanID] and MMPROFILES.ID = OnCallPlanUsers.[ProfileID] and TeamDisplayName like 'Database' and MMPROFILES.PROFNAME like 'hferdi' //Modus,Username,Teamname,ShortDate,Date,TimeStart,TimeEnd EAScriptHost.LogDebug("Modus " + Modus + " " + Username + " " + Teamname + " " + Year + " " + Month + " " +Day + " " + TimeStart + " " + TimeEnd + " ()"); var sDateStart = Year + "-" + Month + "-" +Day + " " + TimeStart + ":00.000"; var sDateEnd = Year + "-" + Month + "-" +Day + " " + TimeEnd + ":00.000"; //Insert into if (Modus.indexOf("Add") > -1 ){ //in die internen Tabelle: OriginatorAddress /*ID OnCallPlanUserID DateStart DateEnd Hierarchy Options 181 20 2017-03-16 16:00:00.000 2017-03-16 17:00:00.000 0 3 */ EAScriptHost.LogDebug("INSERT INTO OnCallPlanShifts (OnCallPlanUserID, DateStart, DateEnd, Hierarchy, Options) Values ((SELECT TOP 1 [OnCallPlanUsers].[ID] FROM [TeamOnCallPlans],[OnCallPlanUsers], MMPROFILES where [TeamOnCallPlans].[OnCallPlanID] = [OnCallPlanUsers].[OnCallPlanID] and MMPROFILES.ID = OnCallPlanUsers.[ProfileID] and TeamDisplayName like '" + Teamname + "' and MMPROFILES.PROFNAME like '" + Username + "'), '" + sDateStart + "', '" + sDateEnd + "',0,3)"); oExec = oConnInternalDB.Execute("INSERT INTO OnCallPlanShifts (OnCallPlanUserID, DateStart, DateEnd, Hierarchy, Options) Values ((SELECT TOP 1 [OnCallPlanUsers].[ID] FROM [TeamOnCallPlans],[OnCallPlanUsers], MMPROFILES where [TeamOnCallPlans].[OnCallPlanID] = [OnCallPlanUsers].[OnCallPlanID] and MMPROFILES.ID = OnCallPlanUsers.[ProfileID] and TeamDisplayName like '" + Teamname + "' and MMPROFILES.PROFNAME like '" + Username + "'), '" + sDateStart + "', '" + sDateEnd + "',0,3)"); allOut = "Standin Inserted"; EAScriptHost.LogInfo("Standin Inserted "); } if (Modus.indexOf("Delete") > -1 ){ //Delete FROM OnCallPlanShifts where OnCallPlanUserID = (SELECT TOP 1 [OnCallPlanUsers].[ID] FROM [TeamOnCallPlans],[OnCallPlanUsers], MMPROFILES where [TeamOnCallPlans].[OnCallPlanID] = [OnCallPlanUsers].[OnCallPlanID] and MMPROFILES.ID = OnCallPlanUsers.[ProfileID] and TeamDisplayName like '" + Teamname + "' and MMPROFILES.PROFNAME like '" + Username + "') and DateStart = '" + sDateStart + "' and DateEnd = '" + sDateEnd + "' and Options = 3 oExec = oConnInternalDB.Execute("Delete FROM OnCallPlanShifts where OnCallPlanUserID = (SELECT TOP 1 [OnCallPlanUsers].[ID] FROM [TeamOnCallPlans],[OnCallPlanUsers], MMPROFILES where [TeamOnCallPlans].[OnCallPlanID] = [OnCallPlanUsers].[OnCallPlanID] and MMPROFILES.ID = OnCallPlanUsers.[ProfileID] and TeamDisplayName like '" + Teamname + "' and MMPROFILES.PROFNAME like '" + Username + "') and DateStart = '" + sDateStart + "' and DateEnd = '" + sDateEnd + "' and Options = 3"); allOut = "Standin deleted"; EAScriptHost.LogInfo("Standin deleted "); } oConnInternalDB.CommitTrans(); oExec = 0; } catch (e) { // catch all thrown errors try { EAScriptHost.LogError("Error processing event. Error message (Exception): " + e.message); if (bInTransInternalDB == true && bInTransInternalDB != null) { oConnInternalDB.RollbackTrans(); } allError = allError + e.message; } catch (e2) { EAScriptHost.LogError("Error processing exception. " + e2.message); allError = allError + e2.message; } } finally { try { // Release all resources at the end of message processing // if (oConnInternalDB != null) { oConnInternalDB.Close(); oConnInternalDB = null; } EAScriptHost.LogDebug("Resources released."); } catch (e3) { EAScriptHost.LogError("Error releasing resources. " + e3.message); } if (oExec != 0) { EAScriptHost.LogError("Error Exited with code: " + oExec); RAContext.SetExecutionResult(RAContext.ExecutionError, allOut + allError, oExec); } else { EAScriptHost.LogInfo("ExecuteCommand: Successful executed values inserted"); RAContext.SetExecutionResult(RAContext.ExecutionOK, allOut, 0); } } } //Returns an ADODB.Recordset object for the specified query function DbGetRS(oConn, strSQL) { // Set some constants var adOpenStatic = 3; var adLockBatchOptimistic = 4; // Declare our variables var oRS; // Create the Recordset object oRS = new ActiveXObject("ADODB.Recordset"); // Populate the Recordset object with a SQL query oRS.Open(strSQL, oConn, adOpenStatic, adLockBatchOptimistic, 0); // Return the Recordset return oRS; } //Gets a date string for the date object // function GetDateString(date) { var strDate = date.getFullYear().toString() + "-" + GetDoubleDigit((date.getMonth() + 1).toString()) + "-" + GetDoubleDigit(date.getDate().toString()) + " " + GetDoubleDigit(date.getHours().toString()) + ":" + GetDoubleDigit(date.getMinutes().toString()) + ":" + GetDoubleDigit(date.getSeconds().toString()) + "." + GetTripleDigit(date.getMilliseconds().toString()); return strDate; } // Gets a double digit for the date // function GetDoubleDigit(strText) { var strOutput; if (strText.length == 1) strOutput = "0" + strText; else strOutput = strText; return strOutput; } function GetTripleDigit(strText) { var strOutput; if (strText.length == 1) strOutput = "00" + strText; else if (strText.length == 2) strOutput = "0" + strText; else strOutput = strText; return strOutput; }
This is it and of course you can adapt this to fit your needs. One very convenient enhancement is to fill in the team names automatically with another script but this is something for another blog article.