- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2018 02:01 PM
I am trying to filter out all emails that a task i related to in a business rule. But I am not able to find a way to filter out all emails that is related to that record. below code is not working. It gives no entry in the log. If I move the same gs.log up before the while it does show up in the log. So I take it that there are something wrong with the line referencing instance.
var task = current.sys_id;
var emails = new GlideRecord('sys_email');
emails.addQuery('instance',task);
emails.addQuery();
while (emails.next())
{
gs.log('email is: ' + task);
emails.u_anonymisation_date = "2099-10-10";
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2018 02:11 PM
You have another addQuery() instead of a query(). Also need an update() for the glide record.
var task = current.sys_id;
var emails = new GlideRecord('sys_email');
emails.addQuery('instance', task);
emails.query();
while (emails.next()){
gs.log('email is: ' + task);
emails.u_anonymisation_date = "2099-10-10";
emails.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2018 02:11 PM
You have another addQuery() instead of a query(). Also need an update() for the glide record.
var task = current.sys_id;
var emails = new GlideRecord('sys_email');
emails.addQuery('instance', task);
emails.query();
while (emails.next()){
gs.log('email is: ' + task);
emails.u_anonymisation_date = "2099-10-10";
emails.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2018 02:31 PM
Thanks. That got one step on the way but I still do have a problem with it. Changed to below code now and when closing a incident this will give no change on the email and it will give 2 log entries which are identical and both are from the "email is: before". I guess it still does not get into the while loop.
var task = current.sys_id;
gs.log('email is: before' + task);
var emails = new GlideRecord('sys_email');
emails.addQuery('instance',task);
emails.Query();
var countEmails = 0;
while (emails.next())
{
countEmails++;
var nowdt = new GlideDateTime();
nowdt.setDisplayValue(gs.nowDateTime());
emails.u_anonymisation_date = nowdt;
emails.update();
gs.log('email is: in while' + task);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2018 02:38 PM
Got it. I missed to correct the Q in query
Thanks a lot rlatorre!