- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 05:28 AM
Hello people!
I came here today to seek some script advice
I have a Business Rule that trigger an email notification for a list of users > The Owner and the Managers of a Public Knowledge base
the conditions:
I am trying to dot walk into it, but it is not working
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('kb_knowledge_base');
gr.addQuery('active','true');
gr.query();
if(gr.next()){
var check = gr.getValue('u_notify_when_someone_subscribes_to_knowledge_base_article');
// gs.log('check is'+check);
if (gr.get(current.sub_obj_id) && check == 1) {
//(gr.get(current.sub_obj_id)){
gs.eventQueue('kb.subscribe.notify.knowledgebase', current.gr.kb_managers.email);
}
}
})(current, previous);
it works when I do
gs.eventQueue('kb.subscribe.notify.knowledgebase', current, gr.owner, gr.kb_managers);
but only for the Owner, I need this email to be sent to the KB Managers too
Right now is sending to empty recipients and is going to send-ignored type
Do you have any ideas of how can I solve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 12:40 PM - edited 01-10-2024 12:52 PM
Yo, @beatricelopes
You have literate over kb_managers, since kb_manager is a list field its contains multiple sysid, not a user object, so we take the sysid and use it to get the user object from sys_user table
var sysidList = gr.kb_managers
// Split the sysidList on ','
var sysids = sysidList.split(',');
// Iterate over each sysid
for (var i = 0; i < sysids.length; i++) {
var sysid = sysids[i].trim(); // Trim any extra spaces
var user = GlideRecord("sys_user");
user.get(sysid);
// Run your code for each sysid
gs.eventQueue('kb.subscribe.notify.knowledgebase', current, user.email);
}
Ill try test it later on PDI instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 12:40 PM - edited 01-10-2024 12:52 PM
Yo, @beatricelopes
You have literate over kb_managers, since kb_manager is a list field its contains multiple sysid, not a user object, so we take the sysid and use it to get the user object from sys_user table
var sysidList = gr.kb_managers
// Split the sysidList on ','
var sysids = sysidList.split(',');
// Iterate over each sysid
for (var i = 0; i < sysids.length; i++) {
var sysid = sysids[i].trim(); // Trim any extra spaces
var user = GlideRecord("sys_user");
user.get(sysid);
// Run your code for each sysid
gs.eventQueue('kb.subscribe.notify.knowledgebase', current, user.email);
}
Ill try test it later on PDI instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 05:04 AM
Good!
I was able to make it work by breaking the line
but I believe your solution is a better practice to apply it!
thank you