
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 12:08 PM
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;
}
}
}());
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 10:44 PM
Thanks Mark,
It works well for me as well although I am using Jakarta.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 01:32 PM
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;
}
}
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 02:11 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 10:07 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2021 03:42 PM
Thanks Mark, 3 years on and this is still helping people 😃