I want to achieve the following logic in my catalog script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 01:54 AM
We have to check whether an attachment is attached prior to submit the catalog form.
And if there is no attachment then , display a message stating "You must attach your Certificate of Completion of the Cribl Fundamentals course."
- Labels:
-
Data Acquisition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 03:14 AM
Hello @taahamushtaq ,
There are 2 ways to achieve this -
1. Without script - Create a variable of type 'Attachment' and make it 'Mandatory = true'.
2. With Script - Define an 'onSubmit' Catalog Client Script.
Client Script:
function onSubmit() {
var catalogItemID = g_form.getValue('sysparm_item_guid');
var demo = new GlideAjax('CheckAttachmentCatalogItem');
demo.addParam('sysparm_name', 'checkAttachment');
demo.addParam('sysparm_catalog_id', catalogItemID);
demo.getXMLWait();
var attachment=demo.getAnswer();
if(attachment == 'yes'){
return true;
} else if(attachment == 'no'){
alert("Please attach a catalog items bulk upload file");
return false;
}
}
Script Include:
Client Callable = True
var CheckAttachmentCatalogItem = Class.create();
CheckAttachmentCatalogItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAttachment: function(){
var gr = new GlideRecord("sys_attachment");
gr.addQuery('table_name', "sc_cart_item");
gr.addQuery('table_sys_id', this.getParameter('sysparm_catalog_id'));
gr.query();
if (gr.next()) {
return 'yes';
}
else{
return 'no';
}
},
type: 'CheckAttachmentCatalogItem'
});
Kindly mark this as Accepted Solution/Helpful if above info. helps in any way and help in closing this thread.
Regards,
Shubham