attachments mandatory based on the Short Description of a Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2025 08:20 AM
attachments mandatory based on the Short Description of a Task and only for one task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2025 08:29 AM
Hi @Dileep Raju ,
To make attachments mandatory for a specific task based on the Short Description, you'll need to use a combination of a UI Policy or Client Script and a Business Rule to enforce this. Here's a straightforward approach using a Client Script:
Client Script: Mandatory Attachments Based on Short Description (Catalog Task)
Create a Client Script
Navigate to System Definition → Client Scripts.
Create a new onSubmit Client Script.
Script Configuration:
Table: Task (or sc_task if it's a catalog task)
Type: onSubmit
(function executeOnSubmit() {
// Define the short description that requires attachments
var requiredShortDescription = "Specific Task Description"; // Replace this with the exact short description
// Get the short description from the form
var shortDescription = g_form.getValue('short_description');
// Check if the short description matches
if (shortDescription === requiredShortDescription) {
// Check for attachments
var attachments = g_form.getAttachments();
if (attachments.length === 0) {
alert("Attachments are required for this task.");
return false;
}
}
// Allow form submission
return true;
})();
How It Works:
Trigger Condition: It checks if the short description matches the specified value.
Attachment Check: If the task matches the required short description, it checks for attachments.
Block Submission: If no attachments are found, it shows an alert and prevents form submission.
If my response was helpful, please mark it as the correct answer and close the thread. This will help others who come across the same issue.
Thanks!
Gaurav Rathaur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2025 10:09 AM
Greetings of the day,
I am getting error when i try to close task after attached attachment
g_form.getAttachments is not a function:
. Could you please help me with this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2025 11:20 AM
You can try this:
1. Create a UI script called: "setAttachmentMandatory". Set UI Type to "All".
Put this in the script section.
(function() {
"use strict";
return {
setAttachmentMandatory: function(isMandatory) {
var isSuccess;
try {
angular.element("#sc_cat_item").scope().c.data.sc_cat_item.mandatory_attachment = isMandatory;
isSuccess = true;
} catch (e) {
isSuccess = false;
//gs.log('setAttachmentMandatory() failed: ' + e);
}
return isSuccess;
},
type: "AttachmentUtil"
};
})();
2. Then Client script... and add this script:
Make sure to check the "isolate script" and set UI Type to "All"
function onSubmit() {
var requiredShortDescription = "Specific Task Description"; // Replace this with your actual description
var shortDescription = g_form.getValue('short_description');
// Only run attachment logic if short description matches
if (shortDescription === requiredShortDescription) {
if (g_form.getValue('test') === 'Yes') {
g_ui_scripts.getUIScript('setAttachmentMandatory').then(function (script) {
script.setAttachmentMandatory(true);
});
} else {
g_ui_scripts.getUIScript('setAttachmentMandatory').then(function (script) {
script.setAttachmentMandatory(false);
});
}
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2025 08:50 AM
Hi @Dileep Raju ,
you should use the GlideAttachment API to verify attachments.
If my response was helpful, please mark it as the correct answer and close the thread. This will help others who come across the same issue.
Thanks!
Gaurav Rathaur