How to make attachment mandatory on 'File Attachment' type field?

shilpa12
Kilo Contributor

Hello experts,

I have a requirement where we need attachment to be mandatory for the creation/submission of a record- but on a 'File Attachment' type field. I could achieve this using a before insert business rule for the Attachment icon on the banner. But I am unable to do the same for this kind of field. Our instance is on London release. Please provide your input on this.

 

PFA ss for reference.

 

BR,

Shilpa

10 REPLIES 10

Sunil B N
ServiceNow Employee
ServiceNow Employee

Hi Shilpa,
Make use of hasAttachements() method on GlideRecord for this.

if (current.hasAttachments() == true) {
    gs.addInfoMessage('There is an attachment');
} else {
    gs.addErrorMessage('There is no attachment');
    current.setAbortAction(true);
}

Cheers,
Sunil B N
P.S: Please mark this as an answer/helpful if it was useful to you.

 

Hi Sunil,

Thanks for the reply.

I have the same BR- before insert on my table. But when I try to attach something using 'Attach Resume' field - which is a 'File Attachment' type field it gives me the following error and does not allow attaching using this field. Please assist how can I make attachment mandatory in this case.

BR,

Shilpa

find_real_file.png

Priyanka136
Mega Guru

Hi Shilpa,

You can make attachment mandatory on the form.

So you have to write Business Rule (Before - insert) , Suppose table is Incident (You can apply to any table according to your requirement)

This is working fine for me

Try this below script :-

(function executeRule(current, previous /*null when async*/) 
{

    if (current.hasAttachments() == true)   
    {   
    gs.addInfoMessage('There is an attachment');   
    }   
    else   
    {   
    gs.addErrorMessage('There is no attachment');   
    current.setAbortAction(true);   
    }

})(current, previous);

find_real_file.png

find_real_file.png

Before Attached documents in Attachment icon.

find_real_file.png

After Attached documents in Attachment icon.

find_real_file.png

After Attachment

find_real_file.png

Let me know if you have any questions.

Please mark it Correct or Helpful, if it works based on impact....!!!!

Warm Regards,

Priyanka

find_real_file.png

www.dxsherpa.com

 

Hi Priyanka,

Thanks for the reply.

I have the same BR- before insert on my table. But when I try to attach something using 'Attach Resume' field - which is a 'File Attachment' type field it gives me the following error and does not allow attaching using this field. Please assist how can I make attachment mandatory in this case.

BR,

Shilpa

find_real_file.png