- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2021 06:03 AM
Hi All,
I am using the below code in a Onsubmit catalog client script to show an alert for attaching a file before submitting the ticket in the portal.
Script:
function onSubmit() {
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label'); //Line3
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert("Please attach file before submitting.");
return false;
}
} catch(e) { //For Service Portal
var count = getSCAttachmentCount();
if(count <= 0) {
alert("Please attach file before submitting.");
return false;
}
}
}
According to Best Practice, we will not be using DOM manipulation , so I need to replace the code. Can I get the alternative solution for the line 3 in the above script by not breaking the existing functionality.
Thanks in Advance,
Shilpa.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2021 03:59 AM
Hi,
I haven't tried with this
let us know if that works well
var attachments = g_form.getFormElement('header_attachment_list_label');
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-12-2021 07:06 AM
Hi,
Glad that my blog has helped.
I hope you must have marked it as helpful and also bookmarked it.
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-12-2021 07:08 AM
Hi Ankur,
Thanks for the response. But
document.getElementsByClassName
is also a DOM method. Please let me know the replacement of the code other than the DOM methods.
Thanks,
Shilpa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2021 07:14 AM
check this link and refer Option 2
Possible Ways for Making an Attachment Mandatory : Service Portal/Native UI
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-16-2021 03:41 AM
Hi
Can I use the below code as the alternative for line
Exisiting : var attachments = document.getElementById('header_attachment_list_label');\\ used DOM
Modified code with out DOM : var attachments = g_form.getFormElement('header_attachment_list_label');
Can you please guide me if I can replace the above sentence.
Thanks in advance,
Shilpa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2021 03:59 AM
Hi,
I haven't tried with this
let us know if that works well
var attachments = g_form.getFormElement('header_attachment_list_label');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader