### CoreSQL WHERE Clause Example Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Example of how to declare a WHERE clause for variables in a business rule. Demonstrates referencing an object's ID. ```sql sc.id=${new.object.objectId} ``` -------------------------------- ### Example Activity DTO Fields Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/activity-list-configuration.html?locale=en-US&q=business+rules Demonstrates example fields that can be configured to display on the activity list, including nested object properties. ```plaintext activity.equipment.name activity.address.city activity.code activity.startDateTime activity.durationInMinutes ``` -------------------------------- ### String Value Variable Type Example Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Example of defining a variable based on ECMAScript 6, with the result converted to a String. This is useful for formatted date/time values or other string manipulations. ```javascript ${moment.tz("America/New_York").format()} ``` -------------------------------- ### Example Business Rule Execution Log Response Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rule-api-three.html?locale=en-US&q=business+rules This is an example JSON response when retrieving execution logs for a business rule. It includes details such as object ID, execution time, status, and execution date. ```json { "objectId": "123DE1D0E7B2498CAD33A417103AD999", "executionTime": 1059, "eventType": "SCHEDULE", "kafkaEventId": null, "status": "SUCCESSFUL", "logMessage": null, "executionDate": "2024-03-26T10:06:51.204+00:00", "userId": null, "clientId": "admin", "requestId": "1a9760d25fe8f9f5" } ``` -------------------------------- ### Object Variable Type Example Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Example of defining a variable as an object of a given type, fetching data from the database. Used when a single object's identifier is needed. ```javascript serviceCall.id = ${serviceCallId} ``` -------------------------------- ### Example: Restricting Input to Uppercase Letters Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/advanced-settings.html?locale=en-US&q=business+rules This example demonstrates how to restrict user input to uppercase letters within the 'validationExpression' for a remarks field. It also includes a custom validation error message and field configuration. ```json { "validationExpression": "${activity.remarks} == undefined || /^[A-Z]*$/.test(${activity.remarks})", "validationErrorMessage": "Need to use only upper case letters!", "name": "activity.remarks", "description": "Remarks", "required": true } ``` -------------------------------- ### Array Variable Type Example Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Example of defining a variable as an array of objects of a given type, fetching data from the database. Useful for scenarios involving multiple related objects. ```javascript serviceCall.businessPartner = ${businessPartner.id} ``` -------------------------------- ### Retrieve Business Rule Execution Logs Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rule-api-two.html?locale=en-US&q=business+rules Use this GET request to retrieve execution logs for a specific business rule of type TWO. Ensure you provide the correct rule ID and account/company details. The response includes details about the execution, such as status, timestamps, and any errors. ```HTTP GET https://{cluster}.fsm.cloud.sap/dc/api/rules/v1/CustomRule/{enter rule id}/executionLogs Headers: Authorization: Access Token needed to check if user has permission to perform requests X-Client-ID: Custom parameter that helps identify the request’s origin. X-Client-Version: Custom parameter that helps identify the request’s version. Query Parameters: account: Account name company: Company name executionDateFrom: Start date of a selected timeframe (e.g. 2024-02-20T08:00:00Z) executionDateTo: End date of a selected timeframe (e.g. 2024-03-20T08:00:00Z) page: Execution log results are returned in pages, with the first page starting at 0 by default. size: Number of execution logs displayed per page. Default size per page is 20 and it can be increased to a maximum limit of 1000. ``` -------------------------------- ### Dynamic Value Variable Type Example Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Example of defining a variable based on ECMAScript 6, specifically for Type THREE. Allows for complex object instantiation or dynamic value assignment. ```javascript ${new Object({attribute:1, event:fsmEvent})} ``` -------------------------------- ### Retrieve Business Rule Execution Logs Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rule-api-three.html?locale=en-US&q=business+rules Use this GET request to retrieve execution logs for type THREE business rules. Specify the rule ID in the URL and provide necessary authentication and account details in the headers. Optional query parameters can filter logs by date range and pagination. ```http GET https://{cluster}.fsm.cloud.sap/cloud-rules-service/api/v1/rules/{enter rule id}/executionRecords Headers: Authorization: Access Token needed to check if user has permission to perform requests X-Account-ID: The numerical ID associated with the account. X-Company-ID: The numerical ID associated with the company. X-Client-ID: custom parameter that helps identify the request’s origin. X-Client-Version: custom parameter that helps identify the request’s version Query Parameters: executionDateFrom: Start date of a selected timeframe (e.g. 2024-02-20T08:00:00Z) executionDateTo: End date of a selected timeframe (e.g. 2024-03-20T08:00:00Z) page: Execution log results are returned in pages, with the first page starting at 0 by default. size: Number of execution logs displayed per page. Default size per page is 10. ``` -------------------------------- ### Example JavaScript Expression for Execution Count Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/build-checklist-report.html?locale=en-US&q=business+rules Demonstrates a valid JavaScript expression to dynamically set the execution count based on the number of activities. This is useful for executing an action successively for all objects in an array. ```javascript `${activities.length}` ``` -------------------------------- ### GET /cloud-rules-service/api/v1/rules/{enter rule id}/executionRecords Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rule-api-three.html?locale=en-US&q=business+rules Retrieves the execution logs for business rules of type THREE. This API allows filtering logs by date range and pagination. ```APIDOC ## GET /cloud-rules-service/api/v1/rules/{enter rule id}/executionRecords ### Description Retrieves the execution logs for business rules of type THREE. ### Method GET ### Endpoint `https://{cluster}.fsm.cloud.sap/cloud-rules-service/api/v1/rules/{enter rule id}/executionRecords` ### Parameters #### Path Parameters - **rule id** (string) - Required - The ID of the rule for which to retrieve execution logs. #### Query Parameters - **executionDateFrom** (string) - Recommend - Start date of a selected timeframe (e.g. 2024-02-20T08:00:00Z) - **executionDateTo** (string) - Recommend - End date of a selected timeframe (e.g. 2024-03-20T08:00:00Z) - **page** (integer) - Optional - Execution log results are returned in pages, with the first page starting at 0 by default. - **size** (integer) - Optional - Number of execution logs displayed per page. Default size per page is 10. #### Headers - **Authorization** (string) - Required - Access Token needed to check if user has permission to perform requests - **X-Account-ID** (string) - Required - The numerical ID associated with the account. - **X-Company-ID** (string) - Required - The numerical ID associated with the company. - **X-Client-ID** (string) - Optional - custom parameter that helps identify the request’s origin. - **X-Client-Version** (string) - Optional - custom parameter that helps identify the request’s version ### Response #### Success Response (200) - **objectId** (string) - Description - **executionTime** (integer) - Description - **eventType** (string) - Description - **kafkaEventId** (string) - Description - **status** (string) - Description - **logMessage** (string) - Description - **executionDate** (string) - Description - **userId** (string) - Description - **clientId** (string) - Description - **requestId** (string) - Description #### Response Example ```json { "objectId": "123DE1D0E7B2498CAD33A417103AD999", "executionTime": 1059, "eventType": "SCHEDULE", "kafkaEventId": null, "status": "SUCCESSFUL", "logMessage": null, "executionDate": "2024-03-26T10:06:51.204+00:00", "userId": null, "clientId": "admin", "requestId": "1a9760d25fe8f9f5" } ``` ``` -------------------------------- ### GET /dc/api/rules/v1/CustomRule/{enter rule id}/executionLogs Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rule-api-two.html?locale=en-US&q=business+rules Retrieves the execution logs for business rules of type TWO. This endpoint allows you to fetch historical execution data for specific business rules, filterable by date range and pagination. ```APIDOC ## GET /dc/api/rules/v1/CustomRule/{enter rule id}/executionLogs ### Description Retrieves the execution logs for business rules of type TWO. ### Method GET ### Endpoint `https://{cluster}.fsm.cloud.sap/dc/api/rules/v1/CustomRule/{enter rule id}/executionLogs` ### Parameters #### Path Parameters - **enter rule id** (string) - Required - The ID of the rule for which to retrieve execution logs. #### Query Parameters - **account** (string) - Required - Account name. - **company** (string) - Required - Company name. - **executionDateFrom** (string) - Recommend - Start date of a selected timeframe (e.g. 2024-02-20T08:00:00Z). - **executionDateTo** (string) - Recommend - End date of a selected timeframe (e.g. 2024-03-20T08:00:00Z). - **page** (integer) - Optional - Execution log results are returned in pages, with the first page starting at 0 by default. - **size** (integer) - Optional - Number of execution logs displayed per page. Default size per page is 20 and it can be increased to a maximum limit of 1000. #### Headers - **Authorization** (string) - Required - Access Token needed to check if user has permission to perform requests. - **X-Client-ID** (string) - Required - Custom parameter that helps identify the request’s origin. - **X-Client-Version** (string) - Required - Custom parameter that helps identify the request’s version. ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the execution log entry. - **clientId** (string) - The client ID associated with the execution. - **customRuleId** (string) - The ID of the custom rule that was executed. - **errorMessage** (string) - Contains an error message if the execution failed, otherwise null. - **eventType** (string) - The type of event that triggered the rule execution (e.g., CREATE_OR_UPDATE). - **executionDate** (string) - The date and time when the rule execution occurred. - **executionTime** (integer) - The time taken for the rule execution in milliseconds. - **objectId** (string) - The ID of the object that was affected by the rule execution. - **requestId** (string) - The unique identifier for the request. - **statusType** (string) - The status of the rule execution (e.g., SUCCESSFUL). - **userId** (string) - The ID of the user who triggered the execution, if applicable. - **variableTime** (integer) - Time spent on variable processing in milliseconds. - **conditionTime** (integer) - Time spent on condition evaluation in milliseconds. - **actionTime** (integer) - Time spent on action execution in milliseconds. ### Example Response ```json { "id": 6749919, "clientId": "admin", "customRuleId": "8911F6FA641D428BBFC88DD0C3733127", "errorMessage": null, "eventType": "CREATE_OR_UPDATE", "executionDate": "2024-03-26T08:07:01Z", "executionTime": 29, "objectId": "107D0D62828C46559742E55B0C8E4F6B", "requestId": "a249ed900d0272af", "statusType": "SUCCESSFUL", "userId": null, "variableTime": 8, "conditionTime": 0, "actionTime": 19 } ``` ``` -------------------------------- ### CoreSQL WHERE Clause with Single Quote Escaping Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Example showing how to escape single quotes within a CoreSQL WHERE clause using a JavaScript replace function, essential for handling remarks or text fields. ```sql sc.remarks LIKE ${new.remarks.replace(/'/g, "'\'")} ``` -------------------------------- ### Calculate Distance Action Parameters Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/calculate-distance.html?locale=en-US&q=business+rules Configure the execution count, origin, destination, and variable names for distance and duration when using the 'Calculate Distance' action. ```text Field | Description ---|--- Execution Count | The execution count determines how often the respective action should be executed. Entering an execution count which is greater than 1 might make sense, if you want to execute the action successively for all objects in an array. Enter a valid JavaScript expression or a number, up to 1000. A valid JavaScript expression for execution count is `${ JS expression }`. For example, `${activities.length}` is valid whereas expressions like `${activities}.length`, or `activities.length` are invalid. Origin | The origin or starting point of the technician (example: `$(technician.location)`). Destination | The destination/location of the activity (example: `$(address.location)`). Distance (in km) Variable Name | The name of the variable used to represent distance (example: `Distance`). Duration (in seconds) Variable Name | The name of the variable used to represent duration (example: `Duration`). ``` -------------------------------- ### Activity DTO v26 Structure Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/activity-list-configuration.html?locale=en-US&q=business+rules Provides the data structure for Activity DTO version 26, outlining available fields and their types for screen configuration. ```plaintext dto ActivityDTO_V26: SyncObjectDTO_V10 { optional ActivityTemplate: guid activityTemplate optional Address: guid address optional BusinessPartner: guid businessPartner optional BusinessProcessStepAssignmentEmbeddedDTO_V26[] businessProcessStepAssignments optional string changelog optional readonly boolean checkedOut optional readonly string code optional Contact: guid contact optional dateTime dueDateTime optional integer durationInMinutes optional dateTime earliestStartDateTime optional dateTime endDateTime optional Equipment: guid equipment optional readonly string executionStage optional string hazardType optional boolean milestone optional string number optional objectref object optional boolean personal optional Activity: guid[] predecessorActivities optional Activity: guid previousActivity optional Project: guid project optional integer projectOrdinal optional ProjectPhase: guid projectPhase optional string remarks optional dateTime reminderDateTime optional Person: guid[] responsibles optional ServiceWorkflow: guid serviceWorkflow optional Shift: guid shift optional Activity: guid sourceActivity optional dateTime startDateTime optional string status optional ActivitySubType: guid subType optional string subject optional Team: guid team optional string timeZoneId optional ActivityTopic: guid topic optional readonly integer travelTimeFromInMinutes optional readonly integer travelTimeToInMinutes optional string type } ``` -------------------------------- ### Efficient Moment.js Date Component Extraction Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/best-practices-business-rules.html?locale=en-US&q=business+rules Use specific methods like .day() for extracting date components when possible. This is more efficient than using format() for simple extractions, though it serves a different purpose and is not a direct replacement. ```javascript ${moment(activity.earliestStartDateTime).day()} ``` -------------------------------- ### Accessing User Language Setting in Business Rules Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Retrieve the language setting configured for a user in the web application. This is useful for personalizing user experiences. ```javascript ${user.settings.Cockpit_SelectedLanguage.data} ``` -------------------------------- ### Accessing ServiceCall Code with Alias in Business Rules Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Demonstrates how to access data using the defined alias 'SCcode' for the ServiceCall code field, after using an inner join query. ```javascript ${activitiesWithSC[i].SCcode} ``` -------------------------------- ### Accessing Default Company Language Setting in Business Rules Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Retrieve the default language setting for the company as configured in the web application. This can be used for setting application defaults. ```javascript ${company.settings['CoreSystems.Language.Default']} ``` -------------------------------- ### Selecting Data with Aliases using Inner Join in Business Rules Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Retrieve data from multiple tables (Activity and ServiceCall) using an inner join and define aliases for overlapping field names. This allows for clearer data access in business rules. ```sql SELECT servicecall.code AS 'SCcode', servicecall.subject AS 'SCsubject', activity.code AS 'ACcode', activity.subject AS 'ACsubject', activity.startDateTime, activity.endDateTime FROM Activity activity INNER JOIN ServiceCall servicecall ON servicecall.id = activity.object.objectId WHERE ( activity.status in ('DRAFT', 'OPEN') AND ( activity.dueDateTime >= now() AND activity.dueDateTime <= DATEADD(now(), '7 days') ) ) Activity.30;ServiceCall.25 ``` -------------------------------- ### Counting Distinct Technicians in Business Rules Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/business-rules-variables.html?locale=en-US&q=business+rules Use an Array variable in 'Advanced Mode' to count the number of distinct technicians assigned to a service call. Ensure the variable type is 'Array'. ```sql SELECT COUNT(DISTINCT p.id) FROM ServiceCall sc JOIN ServiceAssignment sa ON sa.object.objectId = sc.id JOIN Person p ON p.id = sa.technician WHERE sc.id = ${sc.id} ServiceCall.26;Person.21;ServiceAssignment.28 ``` -------------------------------- ### Efficient Moment.js Timezone Offset Calculation Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/best-practices-business-rules.html?locale=en-US&q=business+rules Directly obtain the timezone offset in minutes using utcOffset() and then perform a simple division to convert it to hours. This is more efficient than string manipulation and parsing. ```javascript ${parseInt(moment(serviceCall.startDateTime).tz('Europe/Rome').utcOffset() / 60)} ``` -------------------------------- ### Scheduled Rule with Selective CoreSQL WHERE Clause Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/best-practices-business-rules.html?locale=en-US&q=business+rules Use a scheduled rule with a selective CoreSQL WHERE clause in the trigger to avoid resource-intensive, event-triggered rules that may result in many skipped executions. ```sql SELECT activity FROM Activity activity WHERE activity.status = 'CLOSED' AND DATEDIFF(day, activity.lastChanged, NOW()) <= 3 ``` -------------------------------- ### Inefficient Moment.js Date Formatting Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/best-practices-business-rules.html?locale=en-US&q=business+rules Avoid using the format() function for simple date components like day of the week, as it involves resource-intensive string formatting and localization. This approach is less efficient for extracting basic date information. ```javascript ${moment(activity.earliestStartDateTime).format('dddd')} ``` -------------------------------- ### Accessing Report ID via Response Variable Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/build-checklist-report.html?locale=en-US&q=business+rules Shows how to use a response variable to store metadata of a created report attachment. The ID of the report can then be accessed in subsequent actions using the defined variable. ```javascript `${newReport.id}` ``` -------------------------------- ### Handling Multiple Responses for Calculate Distance Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/calculate-distance.html?locale=en-US&q=business+rules When the calculate distance action is executed more than once, configure variables to store multiple responses for distance and duration. This is available for business rules of type THREE only. ```text Example: `duration` set as object-type `Array` Referenced as an array in the duration or distance section. Example: `duration[${i}]` entered in the duration field And then used in a subsequent action. Example: the `duration[0]` response variable referenced in a Send E-Mail action ``` -------------------------------- ### Inefficient Moment.js Timezone Offset Calculation Source: https://help.sap.com/docs/SAP_FIELD_SERVICE_MANAGEMENT/fsm_admin/best-practices-business-rules.html?locale=en-US&q=business+rules Avoid string manipulations on formatted timezone offsets. This inefficient approach involves formatting the offset to a string, using substring, and then converting back to a number, adding unnecessary overhead. ```javascript ${parseInt(moment(serviceCall.startDateTime).tz('Europe/Rome').format('Z').substring(0,3))} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.