Scheduled job for updating user data in incident, problem and change application

P-Rudenko-SN
ServiceNow Employee
ServiceNow Employee

Dear all,

I need to set up a conditional Scheduled job for updating user data in incident, problem and change application. The job has to check the following conditions: if incident, problem and change records is closed and it's more then 12 month already after the record is closed, then a script must run.

The script has to look for the user records (user id, caller id, first, last name, email etc.) in inc, prob, change applications and update these fields with a constant value called "hidden".

As I don't yet have a huge experience with scripting in SNow, would someone please help me to build a needed scripts.

As a beginning, I've created a scheduled job which is running dayli with a following condition:

var ga = new GlideAggregate('incident');

ga.addAggregate('COUNT');

ga.addQuery('active', 'true');

ga.addQuery('resolved_at', '<', gs.daysAgo(1));

ga.query();

ga.next();

ga.getAggregate('COUNT') !== '0';

For now I've put 1 day rather then 365 in order to test the script. I aslo haven't found Incident Closure date, therefore choosed "resolved at" field.

The following script I've set to run:

var inc = new GlideRecord('incident');

inc.get(inc_sys_id);   // Looking up an existing incident record where 'inc_sys_id' represents the sys_id of a incident record

inc.caller_id.first_name = 'Hidden';

inc.caller_id.last_name = 'Hidden';

inc.updateWithReferences();

I'd be appreciated for any help with the scripts for building it in a proper manner.

Thanks i advance,

Pavlo

1 ACCEPTED SOLUTION

zica
Giga Guru

Let us know if you have further info,


If not, please if you don't mind, mark the answer as helpful / correct so other people with the same query could find it easely


View solution in original post

16 REPLIES 16

Gurpreet07
Mega Sage

Why would you like to update user record. Its actually modifying the user details(first name, last name, email) . Even if the user created an incident a year back .. he may be will be active and may have created recent incidents .. This change will reflect everywhere .. where ever that user been referenced.


I'd need to add bit more information here. I don't need to rename a user related data, but rather anonimyze it or somehow mask after reqired period of record closure time.


What are the options available to anonimyze the data in fields?



Thanks,


Pavlo


Gurpreet07
Mega Sage

Hi Pavlo,



Setting incidents active should work fine for you ... other possible solutions are


1. Create a Security Rule .... It will check id record been updated year back then return false....


you may restrict visibility of complete record, some fields (caller, assignment groups)


2. Before query BR should also work to hide such records.


3. If you still want to update user references... create a user profile with first name , last name   'hidden' and refer that record in such incidents .


zica
Giga Guru

@Gurpreet



The scheduled job will only update the caller field and email field on incident table... not on sys_user table.


In other words, it does not change user record but incident record and will replace the user name on the incident by 'hidden"



If the user has another incident created less than 1 year, the record won't be updated since the addQuery will only retrieve all incidents created over a year.



I do not see how you can update sys_user table from incident table ... Did I miss something ?



@pavlo; just user incident_caller.caller_id = "hidden" to replace the caller name by hidden.


There is no field in incident form ... caller email ... caller name   but caller that actually contains sys_id of user record .. when you try to update caller.<fieldFromUserTable> obviously user record will get update.... Try this yorself.