Attachment on Catalog task

Vaishali 11
Tera Guru

I want to make attachment mandatory on a particular catalog task for only one catalog item. How can I achieve it?

 

Thanks.

Vaishali

1 ACCEPTED SOLUTION

If you're getting the alert even if the attachment is there, then something's not working with the GlideRecord, which most likely comes back to the fact that it's running in a client script.  Here's what a Catalog Client Script would like with a Glide Ajax:

function onSubmit() {
    var st = g_form.getValue('state');
    var sd = g_form.getValue('short_description');
    if (sd == 'Fulfillment Task') { //to only run this for one particular Catalog Task
        if (st == 3) { //to only run this when the State is Closed Complete
            var sysid = g_form.getUniqueValue();
            var ga = new GlideAjax('CheckAttachment');
            ga.addParam('sysparm_name', 'taskAttached');
            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 your Script Include with the Client callable box checked would look like this:

var CheckAttachment = Class.create();
CheckAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, { 
	
	taskAttached: 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'
});

View solution in original post

11 REPLIES 11

I tried that also, still getting the alert, even if the attachment is uploaded.

If you're getting the alert even if the attachment is there, then something's not working with the GlideRecord, which most likely comes back to the fact that it's running in a client script.  Here's what a Catalog Client Script would like with a Glide Ajax:

function onSubmit() {
    var st = g_form.getValue('state');
    var sd = g_form.getValue('short_description');
    if (sd == 'Fulfillment Task') { //to only run this for one particular Catalog Task
        if (st == 3) { //to only run this when the State is Closed Complete
            var sysid = g_form.getUniqueValue();
            var ga = new GlideAjax('CheckAttachment');
            ga.addParam('sysparm_name', 'taskAttached');
            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 your Script Include with the Client callable box checked would look like this:

var CheckAttachment = Class.create();
CheckAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, { 
	
	taskAttached: 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'
});