- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-12-2014 06:21 AM
Through our LDAP connection all accounts created in AD are instantly created in ServiceNow. I had planned to leverage this process to send a kind of "Welcome" email to all new employees/students as they are added to the sys_user table, but I've hit a snag because even though their AD usernames are created their actual email addresses aren't created until midnight when a report is run somewhere by the AD admin and it creates an email account and attaches it to their username.
So what I need to do now is schedule something that checks for newly created accounts in the sys_user table and sends this "Welcome" email at like 4am everyday. I assume it needs to be done maybe through the event registry and the system scheduler, but I really haven't messed with those to features at all so I need some help...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-12-2014 08:20 AM
This is what I would do:
1. create a new "Welcome email sent" True/False field on the User table
2. set the new field to "True" or checked for all your current users
3. create a new Event called "u_send.welcome.email"
4. create a new Scheduled Job (System Definition \ Scheduled Jobs) and select "Automatically run a script of your choosing" in order to create a new "Scheduled Script Execution" record. Set it to run when you want it to.
Script for the Scheduled Job:
(function() {
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery("active=true^emailISNOTEMPTY^u_welcome_email_sent=false");
gr.query();
while (gr.next()) {
gs.eventQueue("u_send.welcome.email", gr);
gr.u_welcome_email_sent = true;
gr.update();
}
})();
That way you don't have to worry about when the record was created and you can easily tell with the new field if the email was sent or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2014 09:35 AM
That's right, and the simplest way to get the proper string is to go to the table you are searching, in this case the User table, and create your filter there to get the proper results.
Once you have it, right click on the right-most Breadcrumb and select "Copy query". A window will pop-up with the query that you can copy and then paste into the addEncodedQuery line.
http://wiki.servicenow.com/index.php?title=Using_Filters_and_Breadcrumbs#Breadcrumbs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2014 08:34 AM
How did that work out for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2014 07:24 AM
It works perfectly. Sends out a nicely formatted email to newly created student accounts every morning at 8am.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2014 07:28 AM
Good, glad to hear that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2014 08:24 AM
in the transform map... couldn't you put an if than statement in the onbefore script...
if (source.mail !='' && target.mail == "" ){fire an event to send welcome letter in here}
instead of .mail use your email variables... not THAT familiar with transform scripts but it seems like this would be easier and wouldn't require any manual action.