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:36 PM
I'm assuming you blanked out your super-secret Catalog Item name only for the screen shot and there really is one populated. If not, you'll want to do that. If you're still not getting your "simran" alert then the task short description is not exactly = "SCC4 access – Close System Attach Logs". I would copy and paste from the task to the script to make sure of spacing, case, etc. The scripts I provided are ones I have in use to enforce mandatory attachments on certain tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 01:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2020 04:23 AM
There must be an explanation. Start your catalog client script like this to verify that it is running, and what it is detecting as the short description.
function onSubmit() {
var short_desc = g_form.getValue('short_description');
alert('Short Description=' + short_desc + '=';
}
Confirm that the alert is
=SCC4 access – Close System Attach Logs=
no extra spaces before or after like
= SCC4 access – Close System Attach Logs=
or
=SCC4 access – Close System Attach Logs =
You can also try just using the beginning, or ending of the short description text in your if condition - in case the dash is throwing it off
if(short_desc.indexOf('SCC4 access') > -1){
alert("simran");
...
or
if(short_desc.indexOf('SCC4 access') > -1 &&
short_desc.indexOf('
Close System Attach Logs
') > -1
){
alert("simran");
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 12:35 PM
Hi,
follow the below link you can find different ways to make attachment mandatory,
please tick applies on catalog task in the client script
please hit help and mark answer as correct based on the impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 12:49 PM
Assuming you are not running this in the Service Portal, change your original onSubmit catalog client script to this.
function onSubmit() {
var state = g_form.getValue('state');
var short_desc = g_form.getValue('short_description');
if (short_desc == "SCC4 access – Close System Attach Logs"){
if (state == '3'){
var sysid = g_form.getUniqueValue();
var ga = new GlideAjax('CheckAttachment');
ga.addParam('sysparm_name', 'attached');
ga.addParam('sysparm_sysid', sysid);
ga.getXMLWait();
var answer = ga.getAnswer();
if(answer == 'false') {
alert("You must attach the required forms prior to closing this task");
return false;
}
}
}
}
Then create a Script Include with the same name as is used in the GlideAjax call, ensuring that the Client callable box is checked. Your script will look like this
var CheckAttachment = Class.create();
CheckAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
attached: function() {
var answer = 'false';
var id = this.getParameter('sysparm_sysid');
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_name', 'sc_task');
attachment.addQuery('table_sys_id', id);
attachment.query();
if(attachment.next()){
answer = 'true';
}
return answer;
},
type: 'CheckAttachment'
});