
- 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 10:17 PM
Hi,
You have to write a ui script and call that from on-submit client script.
Please go through the below link for details.
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2019 10:19 PM
Hi Azamat,
This won't work in service portal because gel is not allowed in portal side; use below approach:
create a UI script
UI Script: AttachmentFunctions
function getPortalAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch(e) {
length = -1;
}
return length;
}
then use onSubmit like this
function onSubmit() {
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('Approval attachment is required in order submit this request!');
return false;
}
} catch(e) { //For Service Portal
var count = getPortalAttachmentCount();
if(count <= 0) {
alert('Approval attachment is required in order submit this request!');
return false;
}
}
}
go to your service portal and within that you must see a theme field; go to that theme
in the related list of JS includes; click new
give some display name; select the UI script you just now created; submit the record
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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 10:36 PM
Just did a test on Kingston out-of-the-box environment to prove this is working. Works instantly!
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
‎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-09-2019 07:28 AM
Thank you Ankur so much, I have been banging my head against that client script for a long time. Thanks to you now I have the fix and it runs perfectly.