SOLUTION: Make Attachment Mandatory in Catalog Item ServiceNow

One of the basic requirement while developing ServiceNow catalog item is To make attachment mandatory in catalog item in ServiceNow or make attachment mandatory on form in ServiceNow. Below I have shared the code which you have to write in catalog client script and in Script Include to separately to implement this functionality or to achieve this functionality on your service catalog item. I have also shared the video below which will provide complete demonstration to implement the required functionality.

How to Make Attachment Mandatory in Catalog Item ServiceNow ?

Paste below mentioned code in your onSubmit Catalog Client Script and on Client Callable Script Include.

Catalog Client Script Code:

function onSubmit() {
 //Type appropriate comment here, and begin script below  
var catalogItemID = g_form.getValue('sysparm_item_guid');

var demo = new GlideAjax('CheckAttachmentCatalogItem');
demo.addParam('sysparm_name', 'checkAttachment');
demo.addParam('sysparm_catalog_id', catalogItemID);

var attachment=demo.getAnswer();
if(attachment == 'yes'){
        return true;
} else if(attachment == 'no'){
        alert("Please attach Image of your Employee Card");
        return false;

Script Include Code:

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'));
if ( {
         return 'yes';
        return 'no';
    type: 'CheckAttachmentCatalogItem'

Please note: Please change class name "CheckAttachmentCatalogItem" accordingly to your script include name. 

Video Demonstration:

I below video we have demonstrated that how we can implement the required functionality in ServiceNow catalog item form.

I hope above code and video demonstration will definitely help you to make the attachment mandatory on ServiceNow form. Still, If you have any doubt or facing any problem to implement the  functionality "make attachment mandatory in catalog item servicenow" you can comment below in the comment box. I will reply on the same and if required we can also connect in hangout to resolve the same.

No comments:

Thankyou !!!!

Powered by Blogger.