How to set state field value in before BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 07:24 PM
Hi Team,
Can anyone help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 07:47 PM
try this
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var checkAttach = new GlideRecord("sys_attachment");
checkAttach.addQuery("table_sys_id", current.sys_id);
checkAttach.query();
if (!checkAttach.next()) {
current.setAbortAction(true);
current.state = previous.state;
current.close_notes = "";
gs.addErrorMessage("Add attachment before closing the task");
}
})(current, previous);
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
01-20-2025 02:45 AM
Hope you are doing good.
Did my reply answer your question?
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
01-15-2025 07:48 PM
when is your BR running?
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
01-15-2025 09:24 PM
Try this code:
(function executeRule(current, previous /*null when async*/ ) {
var checkAttach = new GlideRecord("sys_attachment");
checkAttach.addQuery("table_sys_id", current.sys_id);
checkAttach.query();
if (!checkAttach.next()) {
current.setAbortAction(true);
// Explicitly set the state to "Open" (assuming 1 is the value for "Open")
current.state = 1; // Alternatively, you can use setValue("state", 1)
// Clear the close_notes field
current.close_notes = "";
// Display an error message
gs.addErrorMessage("Add an attachment before closing the task");
}
})(current, previous);