NextGen APIs

POST /work-orders/r1/work-cycles/{workCycleId}/work-orders

Http Verb

POST

Url

/work-orders/r1/work-cycles/{workCycleId}/work-orders

Permissions required

WO Configuration: Edit (fsm.core.workorder.configuration.edit)

Personally Identifiable Information (PII)

No

Sensitive Information

No

Last Modified Version

r1

Released since

2024 W3 (FSM 18.0)

Deprecated since


Removed since


Tech Tags


Business Logic

This API is responsible for creating a new work order and its operations based on a work cycle and its structures.

Automatic Code Calculation

  • If the code field is not provided by the client, it will be automatically calculated by the business logic.

  • If the operationCenterId is not provided in the request payload, the request field code will be ignored, and it will be necessary to call the API POST /work-orders/r1/work-orders/unique-codes to generate the work order code.

Work Order Activation

  • If the field activateWorkOrder is null or false, the work order will be created in the "DRAFT" state. It will be possible to activate it later by calling the API POST /work-orders/r1/work-orders/{workOrderId}/activations.

  • If activateWorkOrder is true, the work order status will be set to either "OPEN" or "RELEASE".

Filtering and Searching Work Orders

  • The id returned in the response payload, or the workCycleId provided as input, can be used to filter and search for the created work order using the standard API GET /work-orders/r1/work-orders .

Work Order Creation

  1. Extract Work Cycle

    • Extract the workCycle record related to workCycle.id = {workCycleId}.

  2. Visibility Check

  3. Work Order Type Check

    • Get workCycle.workOrderTypeId and check if it exists and workCycle.workOrderTypeId.active is true. If not, return error WORKORDERS_031.

      • Set workOrder.typeId = workCycle.workOrderTypeId.

  4. Assign Work Cycle Id

    • Set workOrder.workCycleId = workCycle.id.

  5. Operations Assignment

    • If workCycle.operationsAssignment = "AGGREGATE":

      • Set workOrder.aggregatedDuration = workCycle.workOrderDuration.

      • Set workOrder.aggregatedResidualDuration = workCycle.workOrderDuration.

      • Set workOrder.aggregatedCardinalityId = workCycle.teamCardinalityId.

      • Set workOrder.state = "DRAFT".

  6. Set Remaining Fields

    • Populate the remaining fields from the input request body.

Work Order Operations Creation

  1. Extract Work Cycle Structure

    • Extract the workCycleStructure records where workCycleStructure.workCycleId = {workCycleId}. If no record is found, it will not create any work order operation.

  2. Process Each Work Cycle Structure

    • Ignore records where workCycleStructure.optionalOperation = true.

    • If workCycleStructure.workOrderOperationTypeId.active != true, return error WORKORDERS_033.

    • Set workOrderOperation.workOrderOperationTypeId = workCycleStructure.workOrderOperationTypeId.

  3. Aggregated Operations Assignment

    • If workCycle.operationsAssignment = "AGGREGATE":

      • Set workOrderOperation.teamCardinalityId = workCycleStructure.teamCardinalityId.

      • Set workOrderOperation.defaultDuration = workCycleStructure.defaultDuration.

      • Set workOrderOperation.currentDuration = workCycleStructure.defaultDuration.

  4. Activity Assignment

    • Search in workOrderOperationTypeActivity filtering by workOrder.workOrderTypeId, workOrderOperation.workOrderOperationTypeId, and active = true.

    • Get the first record and set workOrderOperation.activity = workOrderOperationTypeActivity.id.

    • If no record is found, get the value from system settings.

  5. Technical Object Check

    • If workCycleStructure.workOrderOperationTypeId.technicalObjectTypeId is null, get workCycle.workOrderType.technicalObjectTypeId. Otherwise, get workCycleStructure.workOrderOperationTypeId.technicalObjectTypeId.

    • Check if technicalObjectTypeId is an "ASSET" or an "ACCOUNT".

    • If technicalObjectTypeId is "ASSET", and workCycleStructure.repeatable = true, create repeatable work order operations. Otherwise, create a single work order operation.

Repeatable Work Order Operations Creation

  1. Asset Retrieval

  2. Populate Fields for Each Asset

    • Set workOrderOperation.address = asset.addressId.

    • Set workOrderOperation.typeId = workCycleStructure.workOrderOperationTypeId.

    • Set workOrderOperation.workCycleStructureId = workCycleStructure.id.

    • Calculate the order field based on the previous workOrderOperation created for this workOrderId, or set workOrderOperation.order = workCycleStructure.order.

Single Work Order Operation Creation

  1. Address Assignment

    • Set workOrderOperation.address = workOrder.addressId.

  2. Technical Object Assignment

    • Set workOrderOperation.typeId = workCycleStructure.workOrderOperationTypeId.

  3. Work Cycle Structure Assignment

    • Set workOrderOperation.workCycleStructureId = workCycleStructure.id.

  4. Order Field Calculation

    • Calculate the order field based on the previous workOrderOperation created for this workOrderId, or set workOrderOperation.order = workCycleStructure.order.


Verification of Maximum Work Order Operations to be Created

  1. Retrieve the number of work order operations to be created.

  2. Check if this number is less than or equal to the value specified in the company properties company.fsm.workorder.maxOperationWorkCycleCreation. Default value for maxOperationWorkCycleCreation is 50.

  3. If the number exceeds the specified value, return the error code WORKORDERS_038.


Work Order Activation

If activateWorkOrder = true:

  • Check if with workOrder creation, at least one workOrderOperation has been created with it:

    • If yes:

      • Calculate the work order state to set it to "OPEN" or "SCHEDULABLE".

      • Calculate the work order operation state to set it to "OPEN" or "SCHEDULABLE".

    • If not:


Path Parameters

Field

Note

workCycleId


Header Parameters

Default.

Request Body Parameters

Field

Validations

Note

addressId



startDate

 Format: ISO-8601


endDate

 Format: ISO-8601


operationCenterId



description

 Max Length: 80


externalCode

 Max Length: 40


code


If not passed by the client, will be calculated automatically by the business logic.

operationCenterId should be not null

If operationCenterId = null → the request field will be ignored

externalSystemId



notes

Max Length: 4000


urgencyId

Referenced resource id existance check


workCenterId



appointmentStartDate

 Format: ISO-8601


appointmentEndDate

 Format: ISO-8601


activateWorkOrder



Response documentation

Response payload fields

Field

Note

id

 


Response error codes

NOT_FOUND, BASE_0001, BASE_0010, BASE_0011, BASE_0003, WORKORDERS_006, WORKORDERS_010, WORKORDERS_031, WORKORDERS_032, WORKORDERS_033, WORKORDERS_038