- 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-16-2021 04:18 AM
Hi,
like this
function onLoad() {
//Populate the variables with the parameters passed in the URL
//Use the 'getParmVal' function below to get the parameter values from the URL
var glideURL = new GlideURL();
glideURL.setFromCurrent();
var sd = glideURL.getParam('sysparm_short_descr');
var ds = glideURL.getParam('sysparm_full_descr');
g_form.setValue('short_descr',sd);
g_form.setValue('full_descr',ds);
}
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-19-2021 06:38 AM
Thank you Ankur.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 06:39 AM
Hi
I have one more question if u can answer..
which code can I replace the below bold code.(we should not use DOM)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
CustomEvent.fire('OA-DatacenterAssetsDecomm-checkServersInCMDB', {serverNameList: newValue, g_form: g_form});
}
Thanks,
Shilpa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2021 04:11 AM
Hi,
can you share your final script which doesn't use DOM for mandatory attachment which works in 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
‎04-16-2021 04:14 AM
Hi
Sure. Below is the code.
function onSubmit() {
try { //Works in non-portal ui
var attachments = g_form.getFormElement('header_attachment_list_label');
('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('Please attach the requested form before submitting.');
return false;
}
} catch(e) { //For Service Portal
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach the requested form before submitting.');
return false;
}
}
}
Thanks,
Shilpa.