Attachment requirement onSubmit works in Service Catalog but the same doesn't work in ServicePortal.

Azamat M_
Kilo Contributor

Hi all,

I have a client script that's prompts the user to attach a file in order to submit their request. This functionality works as intended in ServiceCatalog 'Try it' view however when the same test case is run on Service Portal the user is not prompted with any message and instead the request gets created without any indication of file attachment.

I have read many of the other posts that are closely related to what I am experiencing however, none of the suggestions have been able to fix this issue for me.

I was wondering if anyone out there has/had similar problems and what did you do in order to fix it? Any help will be much appreciated.

My current code:

function onSubmit() {
    (function(){
        var cat_id = gel('sysparm_item_guid').value;//g_form.getUniqueValue();
        if(g_form.getValue('slbEmergency') == 'nonEmergency'){
            var gr = new GlideRecord('sys_attachment');
            gr.addQuery('table_name', 'sc_cart_item');
            gr.addQuery('table_sys_id', cat_id);
            gr.query();
            if(!gr.next()){
                alert("Approval attachment is required in order submit this request!");
                gr.setAbortAction(true);
                return false;
            }
        }
        }());
        
    }

1 ACCEPTED SOLUTION

Thanks Mark,

It works well for me as well although I am using Jakarta.

Regards

Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

Hi there,

For Service Portal you could use a Catalog Client Script like below.

If you're already on Madrid, also have a look at the new Catalog Item options.

Kind regards,
Mark

function onSubmit() {
  
	if (this.document.getElementsByClassName('get-attachment').length == 0) {
		g_form.addErrorMessage(getMessage('attachment_mandatory'));

		return false;
	}	
   
}

find_real_file.png

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thank you Mark for your reply to my post.

My company is still in Kingston.

 

Unfortunately, when I try to implement your code into ServiceNow client script, it didn't fix it. if you have any other ideas, I would happy to give it a shot... :). Anyhow, thank you for trying once again.

 

Azamat M.

Hi there,

Could you share a screenshot of your Catalog Client Script? Maybe there's something else wrong than the code.

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thanks Mark, 3 years on and this is still helping people 😃