- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2015 12:49 PM
Hi ServiceNow Community Developers,
I have the following situation - I have a Requested Item form (sc_req_item table) that has catalog task (sc_task table) related list. When the work notes changes in the Requested Item form I need to send a notification to the assignment group that is in the catalog tasks related list. Would you please advise as to how do I dot walk from the sc_req_item table to the sc_task table to pick up the assignment group that is in this table and specify that as the group i want emails to be sent to. . I can see the 'Show related fields' link but I cannot tell which field to choose that will let me dot walk to the assignment group that is defined in the catalog task (sc_task) table. Please help.
Thanks,
Johannes
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2015 03:04 PM
you can only dot walk from a child to a parent... which is why this didn't work...
how to get the additional recipients isn't to hard.. write a mail notification script that looks up the people that have tasks assigned to them with that item as a parent then use "email.addAddress("cc",splitThis[i]);" to add the user to the email <put the user in where i have splitThis array>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2015 06:19 AM
Thank you very much guys for all your help. I am currently pursuing Doug's suggestion and will let you know once I am done.
Johannes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2015 12:08 PM
Hi Guys,
Unfortunately Doug's recommendation does not work for me because all the fields that I need in the body of the email come from the sc_req_item table and not the sc_task. I wrote a business rule as Doug advised and on change of work notes from the requested item table my business rule copied the current worknotes to the catalog task table and triggered a notification which was already there for work notes changes and the notification was getting sent. All that works fine however all the fields they want from the email are from the requested item table and i don't think there is an easy way to copy them like I did with the work notes because i will do a lot of update on the catalog task table and some of the fields won't even match.
So what I did was I went back to the other solution that German recommended which was to GlideRecord from request item to task and pick up the assignment group, break it down to users within a group and sent the email to each user, that way the notification is getting sent within the requested items table. I wrote an notification email script and I got it to work (tested it as scheduled job script until i got the output I want from the logs), I then copied that to the notification email script. The only problem I have is how do I call it from within the email notification record. I have an email template that my email notification record uses for the body of the email, do I call it there or do I call it somewhere else. Any examples from people who have done this before would be greatly appreciated, I am under so much pressure for this sprint, need to get it ready for testing tomorrow afternoon. Also would you please take a look at this script, I know it works but I am worried about line the following line
email.addAddress("cc", id.email, id.getDisplayValue());
Please kindly advise.
Thanks Johannes
Script :
var cat = new GlideRecord('sc_task');
cat.addQuery("request_item.number", current.number);
var qc = cat.addQuery('state', '1');
qc.addOrCondition('state', '2');
cat.query();
while (cat.next()){
gs.log ("request item " + cat.request_item.number);
gs.log ("assignment group " + cat.assignment_group.name);
gs.log ("req item " + cat.request_item);
var users = new GlideRecord("sys_user_grmember");
users.addQuery('group', cat.assignment_group);
users.query();
while (users.next()) {
var id = users.user;
gs.log ("users are " + id.name );
email.addAddress("cc", id.email, id.getDisplayValue());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2015 01:30 PM
i don't believe you need the .getDisplayValue()
just setting email.addAddress('cc',id);
should add the sid of the user to the cc list... and get it sent out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2015 02:00 PM
hi Doug, this is what I have now:
var cat = new GlideRecord('sc_task');
cat.addQuery("request_item.number", current.number);
var qc = cat.addQuery('state', '1');
qc.addOrCondition('state', '2');
cat.query();
while (cat.next()){
gs.log ("request item " + cat.request_item.number);
gs.log ("assignment group " + cat.assignment_group.name);
gs.log ("req item " + cat.request_item);
var users = new GlideRecord("sys_user_grmember");
users.addQuery('group', cat.assignment_group);
users.query();
while (users.next()) {
var id = users.user;
gs.log ("users are " + id.name );
email.addAddress("cc", id);
}
}
However when the notification gets sent this is what i see in the email logs:
Body:
<html><head></head><body><p> </p>
<p>Click here to view Requested Item: <a href="https://emcesmdev.service-now.com/nav_to.do?uri=sc_req_item.do%3Fsys_id=d8d492160fadb1001820e388b105...">RITM0011025</a></p>
<p>Number: RITM0011025<br />Description: <br />Opened: 2015-01-13 16:28:46 EST<br />Approval: Approved<br />Stage: Fullfillment</p>
<p>Work notes (Internal discussion): </p><table cellpadding="0" cellspacing="0" style="table-layout:fixed" width="100%"><tbody><tr><td colspan="2"><hr /></td></tr><tr style="background-color:LightGoldenRodYellow;"><td class="tdwrap"><strong>2015-01-13 16:52:05 EST - Johannes Mweli</strong></td><td align="right" nowrap="true"><sup>Work notes (Internal discussion)</sup></td></tr><tr style="background-color:LightGoldenRodYellow;"><td colspan="2"><span style="word-wrap:break-word;display:block;">work notes</span></td></tr></tbody></table><p></p>
<p>
</p><div><hr /></div>
<div>
<p></p>
</div>
<p></p>
<p> </p>
<div> </div>
<p> </p>
<p> </p><div> </div><div style="display:inline">Ref:MSG0019493</div></body></html>
in the email template this is how I call the notification email script:
Click here to view Requested Item: ${URI_REF}
Number: ${number}
Description: ${description}
Opened: ${opened_at}
Approval: ${approval}
Stage: ${stage}
Work notes (Internal discussion): ${work_notes}
${mail_script:users_from_assignment_group}
------------------------------------------------------------------------------------------------------------------------------------------------
The template is in the 'what will it contain' section of the email notification record.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2015 02:07 PM
when you look at the email in the log.. who is in the cc field??
you may have to add this field to the form to see it.