- 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-19-2022 04:26 AM
@rishabh
Glad to know.
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
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 04:51 AM
Done sir, thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2022 06:06 AM
Please mark my response as correct so that it helps other members.
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-20-2022 10:28 PM
@rishabh
Please mark my response as correct so that it helps other members.
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-21-2022 02:26 AM
I already did sir for your very first response, now I did the same for second response also thanks