How to verify Catalog Item request has attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 01:09 PM
I found the below script on different Community postings that checks to see if a Catalog Item request has an attachment. I modified the "if" to match my variable so it checks that the Request Type variable is "Report Submission". When I submit a test request with the Request Type variable set to "Report Submission" and with no attachment, the first alert is popping, so I know the "if" is working,, but after that I get a "There is a JavaScript error in your browser console" message and the request is submitted. The developer console message states "ReferenceError: getSCAttachmentCount is not defined". Can someone tell me what is wrong with the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:27 PM
No need to write the script , if you want to make attachment mandatory for a particular condition then go for UI policy as suggested by @Marcos Kassak .
I have attached the snapshot for better uderstandaing.
1. Create variable with attachment data type .
2. Create the UI policy and give the condition and in ui action need to make mandatory 'tue';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 07:53 PM - edited 12-06-2023 07:55 PM
Hi @chrish5
It's because you haven't created the UI Script yet or haven't linked it to the Portal.
Let's follow these steps below to make your client script works.
1. Create a record in the UI Script [sys_ui_script] table.
Display Name: GlobalCatalogItemFunctions
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
} catch (e) {
length = -1;
}
return length;
}
2. Create new record in the JS Include [sp_js_include] table.
Display Name: Attachment Validation
Source: UI Script
UI Script: GlobalCatalogItemFunctions
3. Navigate to the Portal you're working with in the ServicePortal [sp_portal] table. Open the Theme record.
4. Under the related list of the Theme form, create new JS Includes with the Attachment Validation above [2].
NOTE: Make sure the Isolate script checkbox is unchecked to make it works in the Native UI.
Ref: KB0743672 - How to make attachment mandatory with Service Catalog Item on the Service Portal
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 08:42 PM - edited 12-06-2023 08:42 PM
You can use the Variable type of Attachment and then have a UI policy to make it visible and mandatory when request type variable is report submission
