Restrict duplicate attachment on Service Portal form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 05:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2024 08:43 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-17-2024 07:21 AM - edited ‎09-17-2024 07:23 AM
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