How to addQuery() a document_id type field

davidgustafsson
Tera Expert

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";
}

1 ACCEPTED SOLUTION

rlatorre
Kilo Sage

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(); 
}

View solution in original post

3 REPLIES 3

rlatorre
Kilo Sage

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(); 
}

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);
}

Got it. I missed to correct the Q in query

Thanks a lot rlatorre!