Attachment file type restriction ,file not uploaded but showing in activity log

kalyani23
Tera Contributor

Hi,

In my requirement,I have a field with type attachment, and i wanted to restrict some file type and created br,so now its restircting when i upload it, and showing error msg, but still in activity log it is getting added, but that is not required, can someone provide solution for this.

find_real_file.png

thanks & regards,

kalyani

1 ACCEPTED SOLUTION

Hi,

see if you create BR on sys_attachment it will restrict but not show message

if you create BR on your table it will show error message and not restrict

In that case have both the BRs

1) it would restrict and show error message as well

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Hi,

your BR should be on sys_attachment to abort insertion

before Insert

Condition: current.table_name == 'ZZ_YYu_automation_request_task_table'

Script:

var strfilepdf = current.file_name.indexOf('.pdf');
var strfiledoc = current.file_name.indexOf('.doc');
var strfilexlsx = current.file_name.indexOf('.xlsx');
var strfiledocx = current.file_name.indexOf('.docx');
var strfilezip = current.file_name.indexOf('.zip');
var strfilezipx = current.file_name.indexOf('.zipx');
if(current.size_bytes > 15000000){
	gs.addErrorMessage('Please upload file size within 15 mb');
	current.setAbortAction(true);
}
else if((strfilepdf < 0)&&(strfiledoc < 0) && (strfiledocx < 0) && (strfilezip < 0) && (strfilezipx < 0) && (strfilexlsx < 0)){
	gs.addErrorMessage('Please upload file type of pdf / xlsx / doc / zip');
	current.setAbortAction(true);
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

In that case error msg may not appear for user when any doc if they upload which is not supported. is any other way in which we can do, instead of creating br in sys_attachment table.please suggest.

Hi,

see if you create BR on sys_attachment it will restrict but not show message

if you create BR on your table it will show error message and not restrict

In that case have both the BRs

1) it would restrict and show error message as well

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank u

@kalyani 

Glad to help.

Please mark responses helpful as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader