How to validate attachment file name and its format in Service Catalog?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 12:09 PM
Hello everyone,
I have a requirement to validate the attachment filename and the format, when submitting a request in Service Catalog. It should validate the name as, "filename.xlsx", if it's not the correct filename or format. It should give error message to user and user should not be able to submit a request without proper filename convention. How can I accomplish this using Catalog Client Script? Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 12:11 PM
Hi
for doing this, you need to use DOM manipulation, which is highly not recommended by ServiceNow.
Please refer to the following thread:
Regards
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 12:13 PM
Following links should help
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 12:18 PM
Use below solution
https://community.servicenow.com/community?id=community_question&sys_id=47164f61db1cdbc01dcaf3231f961904
But, please make sure that you do not do GlideRecord() in client script.
Instead, use glide ajax.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 09:03 PM
Hi Farooq,
You can use the below Business rule to complete your requirement.
Before-Insert (Business rule)
Table: Item(sc_cart_item)
In condition give your catalog item name. Just like the below Screenshot
Use the below script.
(function executeRule(current, previous /*null when async*/ ) {
var gr = new GlideRecord('sys_attachment');
gr.addQuery("table_sys_id", current.sys_id);
gr.addQuery('file_name', 'STARTSWITH', 'filename.xlxs');
gr.addQuery('content_type', 'application/xlsx');
gr.query();
if (!gr.next()) {
current.setAbortAction(true);
gs.addErrorMessage("Attachment filename should start with FILENAME and Attachment type should be XLXS format.");
}
})(current, previous);
Please mark as correct if this solves your issue or mark as helpful.
Thanks,
Sailesh J