- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 12:06 AM
Can anyone advise me of an alternative for gel('sysparm_item_guid').value code? Need to make the attachment mandatory in SERVICE PORTAL var sid = gel('sysparm_item_guid').value; var gr_at = new GlideRecord("sys_attachment"); gr_at.addQuery("table_name", "sc_cart_item"); gr_at.addQuery("table_sys_id", sid); gr_at.query(); var res = gr_at.next(); if (!res) { alert("You must have an attachment to submit."); return false; } Appreciate the help. Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 06:16 PM
Hi Bryan,
Please find this thread which is equivalently helpful making Attachment mandatory on submission of the item in both Service Portal and Scoped Application: Require attachment for catalog item in Service Portal
You need to create a new UI Script in Global Application scope and call that in your onSubmit Catalog Client Script. In your case the scripts are given below. You need to leverage your existing logic in the Catalog Client Script.
UI Script:
API Name:GlobalCatalogItemFunctions
Script:
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch(e) {
length = -1;
}
return length;
}
onSubmit Catalog Client Scrip (in Global Scope):
function onSubmit() {
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('Please attach atleast one attachment to proceed');
return false;
}
}
catch(e) { //For Service Portal
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach atleast one attachment to proceed');
return false;
}
}
}
I hope this helps. Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 05:58 PM
Try replacing gel('sysparm_item_guid').value with g_form.getUniqueValue()
scripts using gel, document, location, window, $, $j, angular are all considered DOM manipulation techniques and are not available for use in the Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2017 06:16 PM
Hi Bryan,
Please find this thread which is equivalently helpful making Attachment mandatory on submission of the item in both Service Portal and Scoped Application: Require attachment for catalog item in Service Portal
You need to create a new UI Script in Global Application scope and call that in your onSubmit Catalog Client Script. In your case the scripts are given below. You need to leverage your existing logic in the Catalog Client Script.
UI Script:
API Name:GlobalCatalogItemFunctions
Script:
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch(e) {
length = -1;
}
return length;
}
onSubmit Catalog Client Scrip (in Global Scope):
function onSubmit() {
try { //Works in non-portal ui
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('Please attach atleast one attachment to proceed');
return false;
}
}
catch(e) { //For Service Portal
var count = getSCAttachmentCount();
if(count <= 0) {
alert('Please attach atleast one attachment to proceed');
return false;
}
}
}
I hope this helps. Please mark correct/helpful based on impact