- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 02:51 AM
I want to make attachment mandatory on a particular catalog task for only one catalog item. How can I achieve it?
Thanks.
Vaishali
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 07:33 AM
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'
});- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 03:18 AM
You can add an attachment type variable to the Catalog Item, and only show it on the applicable Catalog Task(s), then have a UI Policy to make this variable mandatory on the Catalog Task. Otherwise, there are lots of posts about using an onSubmit Catalog Client Script with a GlideAjax call to check the sys_attachment table for the particular task to see if there is a record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 04:25 AM
Could you please share the script example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 04:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 04:42 AM
I have created the business rule already but not working.
