Sample Business Rules for Optimization



Intro

Every customer is one step away from using automated scheduling and optimization. Each account created in SAP FSM is by default equipped with standard plugins. Therefore, to “activate” automated scheduling, it is a matter of calling the scheduling framework. This can be done by configuring Business Rules. In case of optimization, Business Rules present a configuration functionality for triggering optimization - essentially, a development kit for configurations. With business rules, you can define the following:

  • trigger: what triggers automated scheduling, and when. A trigger can be an event (e.g. creation of a sick leave) or run in scheduled manner, in which case automated scheduling will run regularly, in intervals.
  • the jobs to be scheduled: you can choose to only schedule jobs that are assigned to a certain technician and are due today (might occur on an event of a technician calling in sick on short notice, in which case you would need to reschedule his work for the current day). Or, in case of scheduled optimization, you might want to only automatically assign jobs that are due within the next days and are of certain type. This selection of jobs to be scheduled is your select statement and is defined in Variables of the Trigger. To learn how to write a select statement, read more about Query API.
  • the logic for scheduling to be applied during optimization: the plugin which is to be taken for the use case. To read more on the concept of plugins go here.
  • time window for the optimization: the time span that needs to be filled with assignments. Might be next business week or upcoming days in case of scheduled optimization or current day, in case of an event-based optimization.
  • partitioning strategy: which units (e.g. teams, regions, service centers, etc.) should be scheduled. Might be all partitions within a Company, e.g. in case of scheduled optimization, or only one partition (e.g. in case one technician is calling in sick and their important jobs for the current day need to be re-assigned to their team members).
  • additional parameters: type of technicians (in-house technicians, crowd workforce, or both), release on schedule: should assignment be automatically pushed to the technicians’ mobile app upon scheduling, etc.

All of those configurations might be fairly complex and require at least basic technical knowledge (e.g. an ability to write a select statement). Being a configuration kit, business rules offer the console in which to work, but the configurations themselves have to be done based on the customer’s specific requirements. To work with business rules, respective training should be considered by the customer.

Attention: the provided business rules are generic and are only intended for testing purposes. To address your business requirements, extensive modifications of the business rules are required and can be introduced by customers themselves (extensive training advised) or with help of implementation consultants. Since configurations such as the select statement are individual for every customer, no sample business rules can pre-define those. Therefore, the select statement in the provided business rules select all jobs (Activities). Depending on the amount of data in your system, that might put high pressure on the autoscheduler and cause performance degradation. Therefore, we recommend to utilize partitions (see Action #1) and introduce additional selection criteria in your select statement (e.g. filter by Due Date of jobs or Status).

You can download business rules for three most common use cases for automated scheduling, follow the described steps to configure them, and test the optimization framework. Thus, this page is only relevant for automated planning and reoptimization - semi-automated planning is a feature that is active by default and does not require any configurations on the customer side.

This document outlines the following:

  • Steps for completing authorization
  • Sample business rules to run automated scheduling and optimization

Create Client Credentials for Oauth2

Background

OAuth2 is an authorization framework that enables applications to obtain limited access to SAP Field Service Management user accounts on an HTTP service.

OAuth2 uses the client secret mechanism as a means of authorizing a client (i.e. the software requests an access token). You might think of it as a secret passphrase that proves to the authentication server that the client app is authorized to make a request on behalf of the user.

In this step you will create a new Client ID in your system, and a Client Secret will be generated for you.


Create Client ID and Secret

  1. Log in with your Administration user.
  2. Navigate to Clients
  3. Click the Create button
    • A Client ID will be created automatically.
    • In the User Groups section, select the drop-down for your company and select the group with admin rights:
    • Click Save.
  4. Copy the Client ID and Client Secret and paste it to a text file on your desktop (e.g. Notepad, TextEdit).

    WARNING: Once you close this screen, you will not be able to retrieve the Client Secret!

  5. Use the arrow to go back to the Clients screen. You should now have a new Client ID in your list of Clients.

Create Client Credentials

  1. You need to encode the client ID and client secret using Base64 Encoding. This encoded string will then be used when the Business Rule requests an access token from the authorization server.
    • Here is an online tool which can be used to encode in Base64.
    • Paste the Client ID and Client Secret into the tool as follows, with the values separated by a colon “:” client_id:client_secret
    • Click the Encode button.
    • Copy the resulting string into your text file. These are your client credentials. You will use it in your business rules later.

Scheduled Planning and Re-optimization

Use case: The customer wants to re-optimize the schedule for all technicians at a specific time (for example, at 1:00am, 30 minutes past every hour, every 15 minutes, etc.)

The following JSON-formatted business rule can be used as a template to create a business rule for reoptimization of scheduled planning:

  1. Select the Business Rule: RE_OPTIMIZE_BY_SCHEDULE
  2. Edit your business rule.
    • Set the “Enabled” switch to “On”.
  3. Scroll down to “Trigger”.
    • Under Frequency, change the setting as required. For example, every hour at 00,15,30,45 minutes past the hour.

      NOTE: you can select multiple time intervals. This will launch the business rule every 15 minutes, allowing you to see how the planning board changes throughout the day.

  4. Click on the “Variables” icon. There, adjust your select statement to specify which jobs (activities) are sent to the optimizer to be scheduled. The select statement in the sample business rule is quite simple and picks activities that are ready to be planned or reoptimized. You can introduce additional selection criteria here, like due dates, priorities, etc. To get more insights on how to write queries consult Writing Queries Finally, specify the version of the services (DTOs) to be taken. You shall find available versions of the DTOs in the public documentation.
  5. Scroll down to “Action #0”.
    • Click on the “Headers” icon. You will see one header name with a header value.
    • Copy the client credentials that you created in the previous section. (This is the Base encoded string in your text file.)
    • Paste the string into the header value field so that it replaces “{paste your client credentials here}”. Do not remove the word Basic.

    Example:

  1. Scroll down to “Action # 1 ”.
    • Update the URL field by replacing “{cluster}” with the appropriate FSM cluster for your demo account.
    • Choose one of the following server clusters:
      • EU (example: `https://eu.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • DE (example: `https://de.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • US (example: `https://us.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • AU (example `https://au.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • CN (example `https://cn.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
    • Click on the “Headers” icon.
    • Locate the header name “x-client-id”.
    • Copy the client id that you created above in the authorization step. Paste the client id value into the header value field.
  1. Expand the “Body” field so it is fully visible.
    • Update the partition names with the partitions you created. Partitions are technically Skills. A partition is created by allocating a specific skill to both a job (Service Call or Activity) and a technician and defining it as a partition-relevant skill in the Partitioning Strategy section of the body:

      Example:

    • Under Resources section, select if you want to assign jobs to internal or crowd technicians (or both) by setting respective parameters to TRUE or FALSE. NOTE: If you select to run autoscheduling with crowd technicians ReleaseOnSchedule parameter should be set to FALSE. For more details check Autoscheduling with Crowd.
    • Click “Update”.
  2. Test your new business rule.
    • To execute the business rule, you can either wait for the scheduled time to arrive, or you can manually execute the business rule. To manually execute the business rule:
    • Open the business rule.
    • Click “Execute”.
  3. Check the planning board and observe the results. The new service calls should be auto-scheduled and released by the optimizer.

Automatically Schedule New Job

Use case: A new job (Service Call or Activity) comes into the queue (for example, from ERP). The business rule is activated to optimize and auto-schedule new jobs as they arrive in the system. This prevents jobs from backing up in the queue awaiting a scheduled planning round.

The following JSON-formatted business rule can be used as a template to create a business rule for automatically scheduling new jobs:

  1. Select the Business Rule: OPTIMIZE_ON_ACTIVITY_CREATE
  2. Edit your business rule.
    • Set the “Enabled” switch to “On”.
  3. Scroll down to “Trigger”:
    • Under Event, if needed, change the type of event, e.g. on Object Create or Update, and the object in question, e.g. Activity or Service Call.
    • Under “Variables”, if needed, provide a select statement to limit jobs to be automatically scheduled, for example, only automatically schedule jobs or high priority or incident type.
    • Specify the object version to be taken. You can find available versions of the DTOs in the public documentation.
  4. Scroll down to “Action #0”.
    • Click on the “Headers” icon. You will see one header name with a header value.
    • Copy the client credentials that you created (This is the base-encoded string in your text file.)
    • Paste the string into the header value field so that it replaces “{paste your client credentials here}”. Do not remove the word “Basic”.

      Example:

  1. Scroll down to “Action # 1 ”.
    • Update the URL field by replacing “{cluster}” with the appropriate FSM cluster for your demo account.
    • Choose one of the following server clusters:
      • EU (example: `https://eu.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • DE (example: `https://de.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • US (example: `https://us.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • AU (example `https://au.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • CN (example `https://cn.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
    • Click on the “Headers” icon.
    • Locate the header name “x-client-id”.
    • Copy the client id that you created above in the authorization step. Paste the client id value into the header value field.
  1. Expand the “Body” field so it is fully visible.
    • Update the partition names with the partitions you created.

      Example:

    • Scroll to the top of the page and click “Update”.
  2. Test your new business rule.
    • Create a new service call for one of the customers you set up in Section 3.1.
    • Check the planning board. The new service call will be auto-scheduled by the optimizer.

Re-optimize on Worktime Overlap

Use case: An exclusive reservation is added for a technician, such as a sick day or customer meeting. Any existing activities overlapped by the new reservation will need to be re-optimized.

The following JSON-formatted business rule can be used as a template to create a business rule for reoptimizing based on worktime overlap:

  1. Select the Business Rule: RE_OPTIMIZE_ON_WORKTIME_OVERLAP
  2. Edit your business rule.
    • Set the “Enabled” switch to “On”.
  3. Scroll down to “Trigger”.
    • Under Event, if needed, change the type of event, e.g. on Object Create, and the object in question, e.g. WorkTime. Under “Variables”, if needed, modify the select statement to determine which jobs (activities) are to be rescheduled when a worktime object is created or updated. For example, the jobs that were scheduled for all technicians that are working in the same partition, or the jobs that were assigned to the affected technician for the entire week.
    • In the sample business rule, only the jobs that were affected by the reservation are rescheduled. This can be found under in an array of activities.
    • Example: select activity from Activity activity where activity.startDateTime < ${workTime.endDateTime} AND ${workTime.startDateTime} < activity.endDateTime AND ${workTime.person} IN activity.responsibles
    • Specify the object version to be taken. You shall find available versions of the DTOs in the public documentation.
  4. Scroll down to “Action #0”.
    • Click on the “Headers” icon. You will see one header name with a header value.
    • Copy the client credentials that you created above in the previous section. (This is the Base encoded string in your text file.)
    • Paste the string into the header value field so that it replaces “{paste your client credentials here}”. Do NOT remove the word “Basic”. Example:
  1. Scroll down to “Action # 1 ”.
    • Update the URL field by replacing “{cluster}” with the appropriate FSM cluster for your demo account.
    • Choose one of the following server clusters:
      • EU (example: `https://eu.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • DE (example: `https://de.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • US (example: `https://us.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • AU (example `https://au.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
      • CN (example `https://cn.coresystems.net/dispatchservice/api/autoscheduler/v1/actions/re-optimize`)
    • Click on the “Headers” icon.
    • Locate the header name “x-client-id”.
    • Copy the client id that you created above in the authorization step. Paste the client id value into the header value field.
  1. Expand the “Body” field so it is fully visible.
    • Update the partition names with the partitions you created.

      Example:

    • Scroll to the top of the page and click “Update”.
  2. Test your new business rule.
    • Trigger Scheduled Planning and Optimization Business Rule and wait till finished
    • Select one technician that has several jobs scheduled for a day
    • Create a new reservation on the planning board for that technician on the same day (for example, a sick day). Make sure the reservation is for the entire day.
    • The originally scheduled service calls will be re-optimized.