This topic describes how the developer created the VBScript rule to determine if a checked-in vehicle requires scheduled maintenance (oil change or major servicing) based on the vehicle's last service mileage, the vehicle's current mileage, and the maintenance interval. A scheduled maintenance service ticket is created in addition to any damage service ticket created in an earlier step.
The full text of the VBScript for this rule appears below.
Try If oProperties.GetProperty("RAObject") Is Nothing Then oResultCode.Value = "FAILED" Else ' set resultcode to END now, and if determined that it should be SERVICED, it will be changed below oResultCode.Value = "END" Dim oRentalAgreementGE As Aptify.Framework.BusinessLogic.GenericEntity.AptifyGenericEntityBase oRentalAgreementGE = CType(oProperties.GetProperty("RAObject"), Aptify.Framework.BusinessLogic.GenericEntity.AptifyGenericEntityBase) Dim currentMiles As System.Int32 = CInt(oRentalAgreementGE.GetValue("ReturnMileage")) Dim oApp As New Aptify.Framework.Application.AptifyApplication (oDataAction.UserCredentials) 'Get service intervals for this Vehicle's Maintence Schedule Dim sSQL As System.String sSQL = "SELECT OilChangeServiceMileage, MajorTuneUpMileage " & _ "FROM " & oApp.GetEntityBaseDatabase("Maintenance Schedules") & ".." & oApp.GetEntityBaseView("Maintenance Schedules") & " ms " & _ "INNER JOIN " & oApp.GetEntityBaseDatabase("Vehicle Models") & ".." & oApp.GetEntityBaseView("Vehicle Models") & " vm ON vm.MaintScheduleID = ms.ID " & _ "INNER JOIN " & oApp.GetEntityBaseDatabase("Vehicles") & ".." & oApp.GetEntityBaseView("Vehicles") & " v ON v.ModelID = vm.ID " & _ "INNER JOIN " & oApp.GetEntityBaseDatabase("Rental Agreements") & ".." & oApp.GetEntityBaseView("Rental Agreements") & " ra ON ra.VehicleID = v.ID " & _ "WHERE ra.VehicleID = " & oRentalAgreementGE.GetValue("VehicleID").ToString Dim dt As System.Data.DataTable = oDataAction.GetDataTable(sSQL) Dim oilMiles As System.Int32 = CInt(dt.Rows(0).Item("OilChangeServiceMileage")) Dim tuneMiles As system.Int32 = CInt(dt.Rows(0).Item("MajorTuneUpMileage")) 'Get last Maintenance Service for this vehicle sSQL = "SELECT TOP 1 VehicleMileage " & _ "FROM " & oApp.GetEntityBaseDatabase("Service Tickets") & ".." & oApp.GetEntityBaseView("Service Tickets") & " st " & _ "WHERE st.VehicleID = " & oRentalAgreementGE.GetValue("VehicleID").ToString & _ " AND st.ServiceType = 'Scheduled Maintenance' " & _ "ORDER BY st.VehicleMileage DESC" Dim lastService As System.Int32 = CInt(oDataAction.ExecuteScalar(sSQL)) 'Determine if Maintenance is required Dim servicesNeeded As System.String If lastService < oilMiles*(currentMiles\oilMiles) Then ' the last maintenance record is earlier than the last required ' oil change for this vehicle, so it is due for an oil change oResultCode.Value = "SERVICE" servicesNeeded = "Oil Change Required" End If If lastService < tuneMiles*(currentMiles\tuneMiles) Then ' the last maintenance record is earlier than the last required ' major tune up for this vehicle, so it is due for a tune up oResultCode.Value = "SERVICE" servicesNeeded &= IIf(servicesNeeded = "", "", System.Environment.NewLine).ToString servicesNeeded &= "Major TuneUp Required" End If 'Set Property for servicesNeeded to be passed to next step If servicesNeeded <> "" Then oProperties.AddProperty("servicesNeeded", servicesNeeded) End If End If Catch ex As System.Exception oResultCode.Value = "FAILED" Aptify.Framework.ExceptionManagement.ExceptionManager.Publish(ex) End Try |
Add Step 4. See Creating Step 4: Create Service Ticket for Service Step.
You will return later to this step to configure its Action Map (see Linking Sample Process Flow Steps Together). Aptify recommends waiting to configure the Action Map until later since there are no next steps to link to yet. |