- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2021 12:49 AM
We are using below catalog client script for mandatory attachments , but as per best practices servicenow asking us to use without gel function in 5th line (var cat_id = gel('sysparm_item_guid').value;)
kindly help me to change below code without gel method
function onSubmit() {
//Type appropriate comment here, and begin script below
var condtn = g_form.getValue('Server_com_decom');
if(condtn == 'Commission'){
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2021 02:01 AM
Hi
Give a final try:
function onSubmit() {
var OwnOther = g_form.getValue('Server_com_decom');
if (OwnOther == 'Commission') {
var cat_id = g_form.getValue('sysparm_item_guid');
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must add an attachment before submitting this request.");
return false;
}
}
}
Thanks
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2021 12:54 AM
Please review
https://community.servicenow.com/community?id=community_question&sys_id=4bb09f69dbdcdbc01dcaf3231f961947
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2021 01:01 AM
You can also get help from
https://community.servicenow.com/community?id=community_question&sys_id=1ac72769db84141cd82ffb243996193c
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2021 01:11 AM
Hi @Nitya
You can try these two below codes:
1) On Submit() client script:
if (OwnOther == 'Commission') {
try {
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
} catch (e) {
}
}
}
Script: onSubmit
Note: Ensure Isolate Script field is set to False for this Catalog Client Script to ensure DOM manipulation works
//Type appropriate comment here, and begin script below
var OwnOther = g_form.getValue('Server_com_decom');
if (OwnOther == 'Commission') {
var countRequired = 1;
if(window == null){
// portal
if(this.document.getElementsByClassName('get-attachment').length != countRequired) {
alert('You must add attachment before submitting this request.');
return false;
}
}
else{
// native view
var length = $j("li.attachment_list_items").find("span").length;
if(length != countRequired){
alert('You must add attachmen before submitting this request.');
return false;
}
}
}
}
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2021 01:17 AM
document.getElementById is DOM manpulated functionality
Servicenow /client are referring to write code with out document.getElementById or gel
As per client script best pratice, Avoid DOM manipulation. Instead of this I want to use Glide form API or some different approach.
kindly help me