- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 05:41 AM
Hello beautiful community!
I have a Business Rule that is based on sc_request for the sake of the notification.
What I need to do is to trigger it based on the choice of a certain catalog item's multiple choice variable called 'requested_resource_type'. So when the user chooses 'technical_project_resource' in 'requested_resource_type' it should trigger the notification.
Here is my BR code:
// Business Rule: Trigger Notification for teknisk_resursprojekt
// When to run: After Insert/Update
(function executeRule(current, previous /*null when async*/) {
// Kontrollera om cat_item har rätt sys_id
if (current.cat_item == '0f0278598c2a1e10ebb6ef259418f246') {
// Hämta relaterade sc_req_item-poster
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.sys_id);
gr.query();
while (gr.next()) {
// Kontrollera om användaren valt "technical_project_resource" i variabel 'requested_resource_type'
var selectedResources = gr.variables.requested_resource_type; // Variabelvärde
if (selectedResources && selectedResources.indexOf('technical_project_resource') !== -1) {
// Trigga eventet 'teknisk_projektresurs'
gs.eventQueue('teknisk_projektresurs', 'custom@email.com', current.requested_for.email, '');
}
}
}
})(current, previous);
The problem; is that it doesn't trigger anything. The requested_for should have gotten the email, but nothing is sent. I've tested with my own custom email in the eventQueue line, but it doesn't trigger to that one either.
What am I doing wrong? Here is the configuration for the BR:
Here is the configuration for the notification:
Thanks in advance! 😎
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 05:53 AM
your BR script is wrong
update as this ->you should query RITM to get the catalog item name
(function executeRule(current, previous /*null when async*/ ) {
// Kontrollera om cat_item har rätt sys_id
var ritm = new GlideRecord('sc_req_item');
ritm.get('request', current.sys_id);
if (ritm.cat_item == '0f0278598c2a1e10ebb6ef259418f246') {
// Kontrollera om användaren valt "technical_project_resource" i variabel 'requested_resource_type'
var selectedResources = ritm.variables.requested_resource_type; // Variabelvärde
if (selectedResources && selectedResources.indexOf('technical_project_resource') !== -1) {
// Trigga eventet 'teknisk_projektresurs'
gs.eventQueue('teknisk_projektresurs', current, 'custom@email.com', ritm.requested_for.email);
}
}
})(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-07-2025 05:53 AM
your BR script is wrong
update as this ->you should query RITM to get the catalog item name
(function executeRule(current, previous /*null when async*/ ) {
// Kontrollera om cat_item har rätt sys_id
var ritm = new GlideRecord('sc_req_item');
ritm.get('request', current.sys_id);
if (ritm.cat_item == '0f0278598c2a1e10ebb6ef259418f246') {
// Kontrollera om användaren valt "technical_project_resource" i variabel 'requested_resource_type'
var selectedResources = ritm.variables.requested_resource_type; // Variabelvärde
if (selectedResources && selectedResources.indexOf('technical_project_resource') !== -1) {
// Trigga eventet 'teknisk_projektresurs'
gs.eventQueue('teknisk_projektresurs', current, 'custom@email.com', ritm.requested_for.email);
}
}
})(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-07-2025 06:52 AM
Hey Mr!
Thanks for the code, unfortunately no notification is triggered still to the requested_for field. But I've logged out the code, and it runns to the end, so I get to the last log before the else:
(function executeRule(current, previous /*null when async*/ ) {
gs.log('Business Rule körs');
var ritm = new GlideRecord('sc_req_item');
if (ritm.get('request', current.sys_id)) {
gs.log('RITM hittad');
if (ritm.cat_item == '0f0278598c2a1e10ebb6ef259418f246') {
gs.log('cat_item matchar');
var selectedResources = ritm.variables.requested_resource_type;
gs.log('requested_resource_type: ' + selectedResources);
if (selectedResources && selectedResources.indexOf('technical_project_resource') !== -1) {
gs.log('technical_project_resource vald');
gs.eventQueue('teknisk_projektresurs', current, 'custom@email.com', ritm.requested_for.email);
}
}
} else {
gs.log('RITM inte hittad');
}
})(current, previous);
Any idea what could be the problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 07:58 AM
is it triggering the event?
Did this log come?
gs.log('technical_project_resource vald');
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-07-2025 09:07 AM
Yes, that log came.