Custom validation script to prevent submit unless a file is attached

Hi,

I want to write a custom script that checks if the number of attached files is greater than xero. If there are no files attached, I want to raise a validation error.

I do recall seeing an example script that does exactly this job, but I can't find it any more. Can some one please offer some guidance on how to get a list of attachments for a given DocType record.


Thank you,
-Jev



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/18085115-52ef-4d75-b450-9b6fdaf2dcaa%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Check this property to see number of attachments:

keys(cur_frm.attachments.get_attachments()).length;





On Saturday, March 8, 2014 3:35:38 AM UTC+5:30, Jev Björsell wrote:
Hi,

I want to write a custom script that checks if the number of attached files is greater than xero. If there are no files attached, I want to raise a validation error.

I do recall seeing an example script that does exactly this job, but I can't find it any more. Can some one please offer some guidance on how to get a list of attachments for a given DocType record.


Thank you,
-Jev



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/3b0c575b-7028-4a25-b4d5-7f20fee6ac3b%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.