How can i restrict particular type of document in attachment?

The Matrix
Tera Contributor

Hii, 

i have a scenario where only PDF files should only get attach to the incident form. How can i achieve this. 

1 ACCEPTED SOLUTION

@Siddharam Takali 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

 

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

View solution in original post

6 REPLIES 6

Hello Sir now i want to restrict docs,png,jpg type attachment and allow pdf and other type how can i get this requirement 

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

// Check if the attachment is related to the incident table
if (current.table_name == 'incident') {
var allowedFileTypes = ['application/pdf', 'application/octet-stream']; // Add more allowed types as needed

var fileType = current.getValue('content_type');

gs.info('Attachment File Type: ' + fileType); // Log the file type for debugging

// Check if the file type is not allowed
if (!allowedFileTypes.includes(fileType)) {
gs.addErrorMessage('Attachment of type ' + fileType + ' is not allowed for incidents.');
current.setAbortAction(true);
}
}

})(current, previous);
using this script all type giving error message 

Thank you so much! Your solution worked perfectly. I really appreciate you sharing it — this saved me a lot of time.