# How to add/update/delete annotations based on condition?

**URL:** <https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950>\
**Category:** Technical Support\
**Created:** [August 15, 2022, 6:11am UTC](https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950 "2022-08-15T06:11:45Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![arman](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@arman](https://pdfjs.community/u/arman)\
**Post date:** [August 15, 2022, 6:11am UTC](https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950/1 "2022-08-15T06:11:45Z")

</div>

**Which product are you using?**  
PDF.js Express

**PDF.js Express Version**  
8.0.1

**Detailed description of issue**  
When the event “annotationChanged” will call, I want to add/update/delete annotations based on conditions otherwise not. But now it always add/update/delete annotations even after I added my conditions.

**Expected behaviour**  
After checking my condition. No annotation should be added/updated/deleted.

**Does your issue happen with every document, or just one?**  
Issue happens with every document

**Code snippet**

```javascript
annotationManager.addEventListener('annotationChanged', (annotations, action, { imported }) => {
      if (imported) {
        return;
      } else if(myCondition){
        // do something and return.
        return;
      } else {
        if (action === 'add') {
        console.log('this is a change that added annotations');
      } else if (action === 'modify') {
        console.log('this change modified annotations');
      } else if (action === 'delete') {
        console.log('there were annotations deleted');
      }
      }
    });

```

Thanks

---

_[View the full topic](https://pdfjs.community/t/how-to-add-update-delete-annotations-based-on-condition/1950)._
