Which Trigger get fired before a file get attached to a doctype?

Hi,
I am looking for a trigger which get fired before a file get attached to a doctype.
Like, I have already written the code to restrict the user to remove any document attached to the item master, if item is in Approved State. Similarly, I want to call it before a file get attached to an Item Master, it should also restrict the user to attach any new document, if the item master is in Approved State.

https://discuss.erpnext.com/t/can-we-run-an-python-script-before-a-file-is-deleted-solved/21545/11?u=ruchin78

I appreciate, if anyone may let me know which trigger I should use for the same.

I have already tried the following but these triggers are not able to call my script written in python:

autoname
before_insert
on_update

Here is my hooks.py

'File': {
    'on_trash': ['library_management.folder_scriptss.check_doc_status'],
    'before_insert': ['library_management.folder_scriptss.check_doc_status']
  }

Regards
Ruchin Sharma

@ruchin78 why did you close this?

If you figured it out, please share the solution for others too!

@rmehta Sorry forgot to mention the same here.

'File': {
    'on_trash': ['library_management.folder_scriptss.check_doc_status'],
    'autoname': ['library_management.folder_scriptss.check_doc_status']
  }

on_trash will be called before any document get removed/deleted.
autoname will be called before File Doctype names any document (before saving it into the database)

So, in this case if you hook the File Doctype with these triggers then these triggers will always be called before the event like. on_trash will be called before any file/attachment/document get deleted and autoname will be called before any file/document get attached.

Regards
Ruchin Sharma

1 Like