Delete from Data Store Entities Smart Service

Overview

This article provides guidance on how to use the Delete from Data Store Entities smart service in your process model. The Delete from Data Store Entities Smart Service lets you delete data in multiple data store entities within the same data store based on your input. The entities to be affected and the data to remove are defined by the Data to Delete node input of type EntityDataIdentifiers. The data are identified by IDs in an array, so only data whose data type has a defined primary key field can be deleted.

This smart service does not produce a node output, but the deletions are added to a new deletion log as described below. If any write to the data store fails, no data is deleted from the data store.

NOTE: Running this smart service irreversibly deletes the identified row(s) from the target entity. The deletion of related data will be based on the JPA annotations/DB schema defined for the entity. For example, deleting the parent in a one-to-many containment relationship also deletes the children, but deleting one side of a lookup relationship will not affect the related object.

  • Also, note that any CDT created through the Data Type Designer or uploaded via an XSD file automatically has the cascade attribute to ALL by default, so unless you have manually changed this setting, deleting a parent record of a CDT with this setting results in the deletion of the parent's child records.

See also: CDT Relationships

Example Use Case

You have an application that manages purchase requests with a process which needs to remove data from three different entities based on cancellations for an account.

When the Account Manager has a call with a customer, he/she updates the status of the different purchase requests to "cancelled" for the customer account.

Using this smart service, you can remove data from all three data store entities within the same transaction. This way, if an error occurs while deleting from one of the entities, the other entities will not be modified. The data is left in a consistent state as if no data was deleted from any entities.

Permissions Needed

The user running the smart service must have at least Viewer rights to the data store that contains the entities defined in the Data to Delete node input. Attempting to complete this task without the proper user rights generates an error message and pauses the task.

Properties

  • Category: Data Services

  • Icon:

  • Assignment Options: Unattended

See also: Smart Services

Configuration Options

This section contains tab configuration details specific to this smart service. For more information about common configurations see the Process Node Properties page.

Data Tab

Node Inputs

Input Data Type Description Required Multiple
Data to Delete EntityDataIdentifiers The target entity and the primary key values of the items to delete.
  • The entity data will be deleted in the order specified in the node input.
  • No Yes
    Deletion Comment Text Additional information to capture in the audit logs.
    For example, if the node is run as an administrator, indicate the user who requested the deletion.
    No No

    You can delete from multiple data store entities in one transaction by creating an array of type EntityDataIdentifiers.

    • All entities defined in the array must be of the same data store.
    • Arrays can be constructed using dictionary syntax at the Entity Data Identifiers level of the node input or populated in the process flow prior to executing this smart service and passed to the node input.

    See also: EntityDataIdentifiers and Dictionary Syntax in Expressions

    Example Input

    If you set the Data to Delete input to delete data in three data store entities, using process variables for the entities and process variables populated in a prior process step for the data values, your input value may resemble this:

    1
    2
    3
    4
    5
    
    ={
    {entity:pv!ENTITY_SPRINT_ITEMS, identifiers:pv!itemIdsToDelete},
    {entity:pv!ENTITY_COMMIT, identifiers:pv!commitIdsToDelete},
    {entity:pv!ENTITY_SPRINT, identifiers:pv!sprintIdsToDelete}
    } 
    

    a!deleteFromDataStoreEntities()

    The Delete from Data Store Entities smart service is available as an expression function that can be executed inside a saveInto on a Interface Component or as part of a Web API.

    Syntax

    a!deleteFromDataStoreEntities(dataToDelete, deletionComment, onSuccess, onError)

    Inputs

    • dataToDelete (List of EntityDataIdentifiers): A list of EntityDataIdentifiers that identify the items to delete.
    • deletionComment (Text): Additional info to capture in the audit logs, for example, if the node is run as an administrator, indicate the user who requested the deletion.
    • onSuccess (Any Type): A list of saves or an HTTP response to execute after the smart service executes successfully. Created with a!save() or a!httpResponse().
    • onError (Any Type): A list of saves or an HTTP response to execute when the smart service does not execute successfully. Created with a!save() or a!httpResponse().

    Deletion Log Output

    Each time this smart service executes successfully, a new line is added to the data_store_deletions.csv log file for each top level item explicitly configured.

    • This does not include a new line for children records in a containment relationship and those automatically deleted with the deletion of the parent.

    The deletion file is located in the following file path:

    <Appian_Home>/logs/audit/*

    Each row in the deletion log contains the following information about the data deletion:

    • Timestamp: The time in which the deletion occurred.
    • User: The username of the user who executed the smart service.
    • Data Store: The name of the target data store.
    • Entity: The name of the target data store entity.
    • ID: The primary key value of the data that was deleted.
    • Process Model Name: The name of the process model that executed the smart service.
    • Process Model ID: The ID of the process model that executed the smart service.
    • Process Name: The name of the process that executed the smart service.
    • Process ID: The ID of the process that executed the smart service.
    • Node Display Name: The node display name of the executed smart service.
    • Node ID: The node ID of the executed smart service.
    • Comment: The deletion comment entered as part of the smart service.
      • Since this smart service runs in unattended mode, Appian recommends adding the user who requested the deletion to the deletion comment.

    NOTE: All information is created in the primary language of the system - not the user's preferred language.

    See also: Deletion Logs

    Run-Time Behavior

    All data is deleted from the data store in the order in which it was given.

    • Casting occurs when the data type of an EntityDataIdentifiers data field does not match the data type of the primary key of the target entity.
    • If any failure occurs during the transaction, all deletions are rolled back and the data in the data store are not deleted.
    • If none of the data fields contain values to delete, one or more identifiers are null, or the EntityDataIdentifiers array is an empty list, no transaction occurs and nothing is recorded in the performance log or deletion log.

    Possible Error Messages

    Casting Errors

    If you receive a casting error, check your EntityDataIdentifiers value. The identifiers in this value must be the primary key value IDs of the data to delete (such as pv!opportunities.id) rather than CDT values (such as pv!opportunities) or else a casting error occurs.

    Constraint Violation Exceptions

    If you receive the following message, it may be due to a constraint violation exception or similar error that occurred while attempting to save data to the database:

    1
    
    An error occurred while trying to delete data. No data was deleted. Details: <exception message>
    

    A constraint violation exception depends on your database schema and may occur when deleting an item that is referenced by another item in the same table via a foreign key.

    Best Practices

    Since this smart service works directly with your data store and custom data types, be sure to note the Schema Design Best Practices before implementing.

    See also: Schema Design Best Practices

    Data Types:

    Smart Services:

    FEEDBACK