- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Is it possible to implement this using a Business Rule: prevent attachments from being added or deleted for RITM records of a specific catalog item when the state is Work in Progress or later?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
yes you can use before insert before delete business rule on sys_attachment
Before Delete and Before Insert
Condition: current.table_name == 'sc_req_item'
Script:
(function executeRule(current, previous /*null when async*/ ) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.table_sys_id)) {
if (ritm.cat_item == 'YOUR_CATALOG_ITEM_SYS_ID' && ritm.state >= 2) { // 2 = Work in Progress
gs.addErrorMessage('Attachments cannot be added for this RITM in Work in Progress or later state.');
current.setAbortAction(true);
}
}
})(current, previous);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ryota , well you can do this in two ways.
1. Client script (for UI effect) on RITM table -
function onLoad() {
// Check if the RITM state is 'In Progress' (value 2, verify in your instance)
if (g_form.getValue('state') == '2') {
g_form.disableAttachments();
}
}2. Using Business Rule (for server validation - this is more preferred since you want to restrict both adding and deleting the attachments)
Before Business Rule
Table - sys_attachment
Update and Delete to be checked -
(function executeRule(current, previous /*null when async*/) {
var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.table_sys_id)) {
// Check if the RITM state is 'In Progress' (value 2, verify in your instance)
if (ritm.state == '2' && ritm.cat_item =='catalog item sys_id') {
gs.addErrorMessage('Attachments cannot be added for this RITM when it is In Progress.');
current.setAbortAction(true);
}
}
})(current, previous);
If my response has helped you, mark it as helpful and accept the solution.
Regards,
Nayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ryota , my solution should have also worked for you.
Kindly accept the solution and closed the thread.
Regards,
Nayan
