- 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-09-2022 04:33 AM
I tried that also, still getting the alert, even if the attachment is uploaded.
- 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'
});