Restrict duplicate attachment on Service Portal form

Balamurugan Pal
Tera Expert

I have a requirement to avoid duplicate attachments on service catalog form on service portal. When users add same attachment twice, it should throw an error on top and restrict the duplicate attachment insertion. I have achieved this with BR on the native UI. But the BR is not working on service portal.

 

How to achieve this via widget scripts? Please help me with this

6 REPLIES 6

@Balamurugan Pal 

you can use onSubmit catalog client script and check that

this script will give you file names and then you can compare within the array

Hope this helps and you can enhance it further

function onSubmit() {
	//Type appropriate comment here, and begin script below
	var arr = [];	
		// portal
		var z = this.document.getElementsByClassName("get-attachment ng-binding ng-scope");
		var k;
		for (k = 0; k < z.length; k++) {
			var value = z[k].innerHTML;
			value = value.substring(0, value.indexOf('('));
			arr.push(value.trim());
		} 
		// now check if the array has duplicate elements or not
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

Thanks for the catalog client script. But I need to add this script to each and every catalog out there in our system. Instead, I want to implement this rule globally to all catalog items.

 

So, If possible, can you share a widget script to check and avoid duplicate attachments?

 

Thanks