Make attachment mandatory for a particular view?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 05:19 AM
we have multiple views created on a table
we need to make attachment mandatory in a particular view only and do not impact other,i know we can use view in client script ,i want to avoid using getxmlwait or gliderecord in client side
Any best practice to make attachment mandatory on a new record on submitting?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 06:07 AM
Hi @Kiran Kumar 76,
Write a on submit client script
if (g_form.getViewName() === 'YourViewName') {
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('Please attach attachment.');
return false;
}
}
Tested in PDI.
I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 07:08 AM
Hi @Community Alums
Thanks tried on workspace ,isnt working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 09:11 AM - edited 05-28-2024 09:15 AM
@Kiran Kumar 76 , I just tried in workspace...not sure why it's not working. But I used onsubmit client script & glideajax as an alternative & it's working in workspace (I tested on Service Operation Workspace). Please try the below
Script Include:
var aa = Class.create();
aa.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hh: function() {
var gr = new GlideRecord("sys_attachment");
gr.addEncodedQuery("table_name=incident^table_sys_id="+this.getParameter('sysparm_id'));
gr.query();
if (gr.next()) {
return true;
} else {
return false;
}
},
type: 'aa'
});
On submit client script:
function onSubmit() {
if (g_form.getViewName() === 'YourViewName'){
var ga = new GlideAjax('aa');
ga.addParam('sysparm_name', 'hh');
ga.addParam('sysparm_id',g_form.getValue('sys_id'));
ga.getXMLAnswer(HelloWorldParse);
return false;
}
}
function HelloWorldParse(response) {
// Handle the response
alert(response);
if (response === "false") {
alert("Attach Attachment");
return false;
} else {
return true;
}
}