Snehal2
Kilo Guru
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 02-02-2020 09:38 PM
Hi Guys,
The following script will allow only image attachments(.jpg, .jpeg, .png) on the service catalog.
>>onSubmit catalog client script:
function onSubmit() {
try
{
//for non-portal
var sysid =g_form.getElement('sysparm_item_guid').value;
var rowcount=0;
var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_name", "sc_cart_item");
attachment.addQuery("table_sys_id", sysid);
attachment.query();
while (attachment.next()) {
rowcount++;
}
if(rowcount==0){ // Missing {}
alert("Please attach Image for submitting this request(.jpg/.jpeg/png format)!");
return false;
}
if(rowcount == 1 && (attachment.content_type.indexOf("jpg") != -1 || attachment.content_type.indexOf("jpeg") != -1 || attachment.content_type.indexOf("png") != -1)){
//alert(attachment.content_type.indexOf("jpg") + ' ,'+attachment.content_type.indexOf("jpg")+'...'+' ,'+attachment.content_type.indexOf("jpg")+ value);
return true;
}
else
{
alert("Attachment should be in only .jpg/.jpeg/png format!");
return false;
}
}
catch(e)
{
//for-portal
if(this.document.getElementsByClassName('get-attachment').length ==1)
{
var value = (this.document.getElementsByClassName('get-attachment')[0].innerHTML).toLowerCase();
//alert(value.indexOf('jpg') + ' ,'+value.indexOf('jpeg')+'...'+' ,'+value.indexOf('png')+ value);
if(this.document.getElementsByClassName('get-attachment').length <1)
{
alert( "Please attach Image for submitting this request(.jpg/.jpeg/png)!");
return false;
}
else if ((value.indexOf('jpg') != -1 || value.indexOf('jpeg') != -1 || value.indexOf('png') != -1))
{
return true;
}
else
{
alert ("Attachment should be in only .jpg/.jpeg/png format!");
return false;
}
}
}
}
You can also refer this article - Possible Ways for Making an Attachment Mandatory : Service Portal/Native UI
Mark this article helpful, if its helpful.
Regards,
Snehal
Labels:
- 3,343 Views
Comments
ClareM
Tera Expert
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
03-30-2023
06:16 AM
This works well for checking the file correct file type is attached when the Portal settings Mandatory attachment box is checked, however I can't get it to work where Portal settings Mandatory attachment box is not checked and there are no attachments. I have a requirement where attachments are only mandatory for certain form field selections