# Writing script to prevent attachments over 35MB from syncing from Salesforce to ADO/JIRA

**URL:** <https://community.exalate.com/t/writing-script-to-prevent-attachments-over-35mb-from-syncing-from-salesforce-to-ado-jira/5663>\
**Category:** General Questions\
**Tags:** onpremise-jira, cloud-salesforce, exalate, usecase, migrated\_question, moved\
**Created:** [November 4, 2024, 8:20am UTC](https://community.exalate.com/t/writing-script-to-prevent-attachments-over-35mb-from-syncing-from-salesforce-to-ado-jira/5663 "2024-11-04T08:20:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 8:20am UTC](https://community.exalate.com/t/writing-script-to-prevent-attachments-over-35mb-from-syncing-from-salesforce-to-ado-jira/5663/1 "2024-11-04T08:20:17Z")

</div>

_Originally asked by Kaleigh Garcia on 08 April 2024 [(original question)](https://oldcommunity.exalate.com/questions/107970667)_

* * *

Hello! I’m new to writing Groovy and looking for assistance in writing some script in preventing attachments over 35MB from being able to sync bidirectionally from Salesforce to ADO/Jira. We receive a Bad Gateway Error that makes our Console completely inaccessible when a large attachment sync amongst one of our connections. Any guidance is appreciated.

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 8:20am UTC](https://community.exalate.com/t/writing-script-to-prevent-attachments-over-35mb-from-syncing-from-salesforce-to-ado-jira/5663/2 "2024-11-04T08:20:18Z")

</div>

_Answer by Andrea Mura on 24 April 2024_

Hi!

this is the way I filter outgoing attachments on the Salesforce side towards Jira, I hope it’s useful to you!

```auto
def remoteAttachments = entity.attachments.findAll { attachment ->
         replica.filename = attachment.filename
         String fileName= attachment.getFilename()
         replica.estensione = fileName
attachment
}
 
//The max size of the attachments in bytes. 1MB = 1.000.000 bytes
def maxFileSize = 300000000
def refacturedList = []
for(file in remoteAttachments){
    if(file.filesize <= maxFileSize){
        refacturedList.add(file)
    }
}
replica.attachments = refacturedList

```

* * *
