- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 07:18 AM
An error (image named 'error on sp' attached) is displaying on the service portal while submitting the request for validating attachment dependent on variable value (if the variable value is yes, then pop up a message - 'attach a doc.', & if no, then successfully request submitted with req. no generate).
This successfully works on trying it of that catalog item but this is not working on service portal it shows error 'There is a JavaScript error in your browser console' (image attached), after checking in console (image attached) regarding error its written 'while running Client Script "setattachment": ReferenceError: getSCAttachmentCount is not defined'
I wrote the below script as a catalog client script with UI type- 'All', Isolate Script= 'false' (when I make isolate script=true, then it shows an error during submitting for both in catalog item as well as an in-service portal, but when it sets false then it only works on catalog item but not in sp)
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('is_attachment_reqd') == "Yes") { //update field values
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
g_form.addErrorMessage('plz attach doc.');
return false;
}
} catch (e) { //For Service Portal
var count = getSCAttachmentCount();
if (count <= 0) {
g_form.addErrorMessage('plz attach doc.');
return false;
}
}
}
}
My need is when someone selects 'Yes' in catalog item variable 'is_attachment_reqd' & without attachment, if we try to submit the request then it shows error message 'plz attach doc.' & attachment becomes mandatory & when selects 'No' then it easily take request submission.
Kindly help me to fix the issue so that it can run on both UI types successfully. Thanks in advance
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 07:13 PM
then check my blog and use that script.
it works in both native + portal
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
‎01-18-2022 07:30 AM
Hi,
did you follow all the steps for that UI script?
check below link for the steps
Require attachment for catalog item in Platform and Service Portal
also check my blog which would work in both Native + portal; enhance for your requirement
If it helped please mark blog as helpful and also bookmark
Verify Mandatory Attachments Count on Catalog Item
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
‎01-18-2022 11:10 AM
Thanks for your response sir, please be informed that at first, I tried 'Require attachment for catalog item in Platform and Service Portal' but the same error occurred then only I switch to below single catalog client script with ui type= all & isolate script="false"
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('is_attachment_reqd') == "Yes") { //update field values
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
g_form.addErrorMessage('plz attach doc.');
return false;
}
} catch (e) { //For Service Portal
var count = getSCAttachmentCount();
if (count <= 0) {
g_form.addErrorMessage('plz attach doc.');
return false;
}
}
}
}
please help me to run the same script on the service portal as well, current below error is displaying, & after checking the console below screenshot error is showing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2022 07:13 PM
then check my blog and use that script.
it works in both native + portal
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
‎01-19-2022 03:35 AM
Thanks its working now