Insight - automatically delete Objects that are not created by Import tasks
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Purpose
Some organizations have a requirement to only retain assets that got loaded from certain external imports, and to delete the assets located in other sources (or created manually). The requirement becomes even more complex if an asset can be updated from several different sources.
This article provides guidelines on how to:
- Configure Insight to mark Objects for deletion if they are missing and not found in other import source either, and
- Delete those Objects automatically if they are marked for deletion.
Solution
The idea is to introduce a boolean attribute, that will indicate whether an Object is missing and is therefore flagged for deletion. We will use the Insight Import specific behaviour where a "false" boolean value is set to an boolean attribute for every Object that has its identifier present (in other words, for every Object that will be present in the import source).
Step-by-step guide
- In your Object Schema, create a boolean attribute that will serve to mark an Object for deletion. Do note, since the Import assigns "false" value to the attribute for Object that exists, we need to invert the naming logic - which is why in this example, we will use name "Attribute marked for deletion":
- In the Import rule:
- Set "Missing objects: Update" policy > select "Asset marked for deletion" in "Attribute to edit" field > set "true" in "New value of attribute to edit" field. This will make sure that the Object gets marked as missing if it is still not found after the threshold has been reached.
- Set Threshold as per your needs, so that the Object gets marked for deletion after the threshold has been reached
- Map the identifier locator to the boolean attribute "Asset marked for deletion". The attribute will adopt value "false" for every Object that is located in the source (which means the Object exists).
- Repeat this procedure for other Import rules, in case you are updating the same assets from multiple Import sources.
- Now, set up an Insight Automation rule, that will run with the trigger you desire, look for objects marked for deletion and invoke a DELETE REST request to Insight REST endpoint designated to delete the object with the current Object ID (
<baseURL>/rest/insight/1.0/object/${objectId}
) - check REST API documentation for more information.
Notes
- Automation trigger can be set to run after all imports updating the Objects have already run
- For example, if we have 2 imports running at the same day, we can schedule the Automation to clean the Objects afterwards (during the night or the next day).