- 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:19 AM - edited 12-08-2022 05:35 AM
Hello Vaishali,
Write a "Business rule before update" on sc_task table.
Script:
if (!(current.hasAttachments() == true)) {
gs.addErrorMessage('Attachment is mandatory');
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 03:23 AM
This Business Rule would prevent a Catalog Task from being created if it doesn't have an attachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:20 AM
For the above requirement, I have created this script, but it's giving the pop-up even if the attachment is there :-
function onSubmit() {
var cat_id = g_form.getUniqueValue();
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item"); //"sc_cart_item"
gr.addQuery("table_sys_id", cat_id); // cat_id
gr.query();
if (gr.next()) {
alert("Please attach the required Central Express Survey before closing the task.");return false;}
}
Any updates on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 04:16 AM
GlideRecords in a client script are not advisable/supported, so technically you should change this to a GLideAjax call to a script include. In any event, the query is looking for a record on the attachment table that matches the current request, then alerting if a record is found, so you'll want to instead use
if(!gr.next()) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 04:32 AM
Could you please share the snippets of script include and client script.