- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 03:17 AM
Hi Guys ,
I have requirement where if there is no attachment on the 'sc_task' use it should not be able to move state to close complete.
I have written a business rule for that:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 03:42 AM
HI @tGhadage
Please use this script because this query is wrong attachment_file.addQuery('sys_id',gs.userID);
(function executeRule(current, previous /*null when async*/) {
var attachment_file = new GlideRecord('sys_attachment');
// Query for attachments related to the current record
attachment_file.addQuery('table_sys_id', current.sys_id); // Query based on the current record's sys_id
attachment_file.query();
if (!attachment_file.hasNext()) {
gs.addErrorMessage('Please attach the Laptop/Desktop retrieval checklist before closing the task');
current.state = previous.state; // Revert state if no attachments are found
current.setAbortAction(true); // Prevent closing the task
}
})(current, previous);
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 03:56 AM
Hi @tGhadage
Use below script to resolve your issue,
(function executeRule(current, previous /*null when async*/) {
var attachment_file = new GlideRecord('sys_attachment');
attachment_file.addQuery('table_sys_id', current.sys_id);
attachment_file.query();
if (!attachment_file) {
current.state = previous.state;
gs.addErrorMessage('Please attach the Laptop/Desktop retrival checklist before closing the task');
current.setAbortAction(true);
}
})(current, previous);
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 03:42 AM
HI @tGhadage
Please use this script because this query is wrong attachment_file.addQuery('sys_id',gs.userID);
(function executeRule(current, previous /*null when async*/) {
var attachment_file = new GlideRecord('sys_attachment');
// Query for attachments related to the current record
attachment_file.addQuery('table_sys_id', current.sys_id); // Query based on the current record's sys_id
attachment_file.query();
if (!attachment_file.hasNext()) {
gs.addErrorMessage('Please attach the Laptop/Desktop retrieval checklist before closing the task');
current.state = previous.state; // Revert state if no attachments are found
current.setAbortAction(true); // Prevent closing the task
}
})(current, previous);
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 03:56 AM
Hi @tGhadage
Use below script to resolve your issue,
(function executeRule(current, previous /*null when async*/) {
var attachment_file = new GlideRecord('sys_attachment');
attachment_file.addQuery('table_sys_id', current.sys_id);
attachment_file.query();
if (!attachment_file) {
current.state = previous.state;
gs.addErrorMessage('Please attach the Laptop/Desktop retrival checklist before closing the task');
current.setAbortAction(true);
}
})(current, previous);
If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.
Best Regards,
Krushna Birla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 04:33 AM
hi ,
have used our updated script but still its not working.
here is the script :