- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 12:55 AM
Hi All,
I am having a requirement to make the attachment clip mandatory while submitting the request once a particular check box is selected.
Firstly, i wrote a onSubmit catalog client script with the below code but this is working on desktop view but it isn't working on the Employee Center Service Portal.
if (g_form.getValue('sbx_crr_requestType') == 'Manual Letter Generation for Address correction Requests') {
try {
var cat_id_return = gel('sysparm_item_guid').value;
//alert('Happy '+cat_id_return);
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id_return);
gr.query();
if (!gr.next()) {
alert("Please attach the Letter File to proceed further.");
return false;
}
I know 'gel' isn't supported by Service Portal so i did search in the community and found one solution to create a UI Script and call it in the catalog client script, but this also isn't working.
UI Script:
API Name: GlobalCatalogItemFunctions
function getSCAttachmentCount() {
var length;
try {
length = angular.element("Copies/Reprints Request").scope().attachments.length;
} catch(e) {
length = -1;
}
return length;
}
Catalog Client Script
if (g_form.getValue('sbx_crr_requestType') == 'Manual Letter Generation for Address correction Requests') {
try {
var cat_id_return = gel('sysparm_item_guid').value;
//alert('Happy '+cat_id_return);
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id_return);
gr.query();
if (!gr.next()) {
alert("Please attach the Letter File to proceed further.");
return false;
}
} catch (e) { //For Service Portal
var count = getSCAttachmentCount();
if (count <= 0) {
alert('Please attach the Letter File to proceed further.');
return false;
}
}
}
Can someone please let me know how to achieve this solution.
Thanks,
Rooma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 01:30 AM
function onSubmit() {
if (g_form.getValue('sbx_crr_requestType') == 'Manual Letter Generation for Address correction Requests') {
try {
var cat_id_return = g_form.getParameter("sysparm_item_guid");
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id_return);
gr.query();
if (!gr.next()) {
alert("Attachment is mandatory");
return false;
}
} catch (e) {
if (this.document.getElementsByClassName('get-attachment').length == 0) {
g_form.addErrorMessage(getMessage('Attachment is mandatory'));
return false;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 03:36 AM
Any update to this?
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2025 03:44 AM
Using GlideRecord is not recommended in client script.
It will be flagged in health scan report of the instance.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 04:43 AM
As per new community feature you can mark multiple responses as correct.
I provided the correct solution as well to your question.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader