How can I make attachments mandatory on a task?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 12:13 PM
I'm trying to make attachments mandatory on a certain task. I used a catalog client script for this but it's not working. Is there something wrong with my script?
function onSubmit() {
var state = g_form.getValue('state');
var i = 0;
var short_desc = g_form.getValue('short_description');
if (short_desc == "SCC4 access – Close System Attach Logs"){
alert("simran");
if (state == '3'){
var sysid = g_form.getUniqueValue();
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id',sysid);
attach.query();
while(attach.next()){
i++;
}
if (i >=1 ){
return true;
}
else {
alert("You must attach the required forms prior to closing this task");
return false;
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:15 PM
Yes, you can but which user should be auto-populated? Logged in user?
You can use the same approach of Display Business Rule & onLoad() client script for getting the user value populated in Assigned To field.
Also, if it is not in attachments context so I would suggest you to keep it as a separate thread so as to avoid mix of issues which may confuse future readers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:18 PM
The form did not reload with
action.setRedirectURL(current);
when placing this after:
current.setAbortAction(true);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 12:31 PM
Hi,
Try like this in your onSubmit script.
function onSubmit(){
if (this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('attachment_mandatory'));
return false;
}
}
Mark the comment as a correct answer and helpful if this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:24 PM
Hello Simran,
Did you try the solution that i gave above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:32 PM
I don't think that part of the script is the issue. My alert("simran") is not popping up for the task where it checks for that short description