$customHeader
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

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.

  1. Place a rule-based step on the Process Flow's Design tab.
  • See "Creating Process Flow Steps" on page 26 for more information on adding steps to the process flow.
  1. In the Properties area, enter the step's Name and enter the step's description on the Description tab:
  • Name: Check Rental Agreement Return Mileage
  • Description: This step will compare the Rental Agreement's Return Mileage against the Vehicle's assigned Maintenance Schedule to determine if Scheduled Maintenance is required.
  1. Click the Rule tab and select VBScript as the Rule Type.
  2. Enter the VBScript that provides the step's logic. Use the Available Objects and references (accessible from the Scripting toolbar) as necessary.
  • See "Writing Process Flow Step Rules" on page 29 for more information on writing process flow scripts.
  • The full text of the VBScript for this rule appears below.

Code Block: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

  • The script performs the following function:
  • Determines if the RAObject GE object is empty. If so, the rule selects a Result Code of FAILED.
  • Sets the Result Code to END. This can be changed later in the rule if it is determined that the vehicle needs servicing.
  • Retrieves the current vehicle mileage from the Rental Agreements object.
  • Retrieves the Oil Change and Major Tune Up mileage frequencies for the returned vehicle's maintenance schedule from the database.
  • Retrieves the vehicle's mileage for the last maintenance service ticket linked to that vehicle from the database.
  • Determines if an oil change is required for this vehicle by comparing the vehicle's mileage at the last servicing against the current mileage and the oil change interval. If the vehicle requires an oil change, the rule selects a Result Code of SERVICE and writes "Oil Change Required" to a ServicesNeeded string that will be passed an output to the next step.
  • Determines if a major tune up is required for this vehicle by comparing the vehicle's mileage at the last servicing against the current mileage and the major tune up mileage interval. If the vehicle requires a major tune up, the rule selects a Result Code of SERVICE and writes "Major TuneUp Required" to a ServicesNeeded string that will be passed an output to the next step.
  • If not blank, adds the ServicesNeeded string to the Process Flow's Context Object (an Output Property) to be used in Step 4. Note that a single vehicle can qualify for an oil change and a tune up in one service ticket. In this case, the ServicesNeeded output will contains both the "Oil Change Required" text and the "Major TuneUp Required" text.
  • For debugging purposes, the rule adds the ServicesNeeded string to the Rental Agreement's CheckOutComments field. If ServicesNeeded is blank, the rule adds the "NO SERVICE NEEDED" string to the CheckOutComments field.
  • Finally, if the rule fails to execute for another reason, the error is captured by Aptify's Exception Manager for logging and the rule selects the Result Code of FAILED.
  1. Add RAObject as a custom input map to the step's Properties tab.
  • RAObject is one of the Process Flow's Input Properties that is populated by the Event Handler when the event fires. By specifying the input map, the rule can retrieve this object from the Process Flow's Context Object. Therefore, the Source for this Input Property is Context Object and the Source is the RAObject object.
  1. Add ServicesNeeded as a custom output property to the step's Output Map tab.
  • The text generated for the ServicesNeeded string needs to be passed to the new Service Tickets record (created in Step 4). In order to pass this value to the next step, add the property to the Context Object (that is, use a Destination Type of Context Object). In Figure 16.6, the Output Property name defined in the rule is the same as the Destination name that will be used within the Context Object. Output Property from Rule
  1. Save the Process Flows record.
  2. Add Step 4. See "Create Step 4: Create Service Ticket for Service Step" on page 444.Tip: You will return later to this step to configure its Action Map (see "Link Steps Together" on page 447). Aptify recommends waiting to configure the Action Map until later since there are no next steps to link to yet.
  • No labels