- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 11-30-2018 03:29 AM
So in the London release SN have gotten strict with the scripting they are allowing us to use for DOM manipulation.
I;ve seen loads of posts over the last couple of days on how to make an attachment mandatory for a catalog item in both the CMS portal and the Service Portal BUT none were working for me. I had other catalogue (catalog for you from the US of A) client scripts that worked but if i copied them to apply the script to my new catalogue item they didn;t work. I'm already follically challenged and currently suffering from a back back so there was little i could do to let out my frustrations apart from continually trying to retype script after script, reading countless community articles to no avail and try in on various instances where some worked and some didn't.
SO after that little ramble I established that this was London specific. I also found an old pre-London inactive catalogue client script that I corrected with the script I needed to make the attachment mandatory and it worked!!!! What why did it work but a brand new script did not i hear you ask.
Well with the introduction of London came a new hidden field called 'isolate script'. I would not claim to be a complete techy, i can write some javascript and a bit of html but never hand much more training then some code academy and getting completely confused on the SN Script Course, so even though there is a message that appears:
"New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. To disable this feature for all new globally-scoped client-side scripts set the system property "glide.script.block.client.globals" to false."
in all honestly I didn't really understand all of it let alone know that the script i was writing fell into this loop hole.
So long story short if you want to to make the attachment mandatory on the CMS Portal you can use this:
function onSubmit() {
var need = g_form.getValue('attachment_needed'); //if you need it to be related to variable answer
if (need == 'Yes'){ // as above comment
var cat_id= $('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 forgot the attachment moron"); //or use your UX friendly alert whatever
return false;
}
}
} //only needed if using the if query
Now for the portal you can use this BUT the below I haven't actually used yet in London but to be safe would could make two catalogue client script, this for Portal and the above just for Desktop:
function onSubmit() {
//Works in non-portal ui
try {
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert("Attachment???");
return false;
}
}
//For Service Portal
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0) {
alert("Attachment???");
return false;
}}}
DON'T FORGET UNTICK 'ISOLATE SCRIPT'
I hope this helps at least one of you
- 1,872 Views