- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 01:01 AM
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
Solved! Go to Solution.
- Labels:
-
Discovery
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 04:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 04:18 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 06:56 AM
Hi Pavlo,
See if this scheduled job works for you !
function todaysDate(){
var now = GlideDate(); //Now Date
return now.getLocalDate();
}
//var currentDate = getNowDate();
var closedDate = new GlideDate();
closedDate.setValue(todaysDate());
closedDate.addDays(-365); // going back 365 days from today's date
var inc = new GlideRecord("incident");
inc.addQuery('closed_at' , closedDate);
inc.query();
gs.log("@@@@ Row count is : " + inc.getRowCount());
while(inc.next())
{
inc.short_description = 'Test_arnab_snow 321';
inc.caller_id = 'Guest';//make sure this value is present in the sys_user table. for you it is 'Hidden'.'Hidden' must be present in the user table
inc.update();
}
Thanks,
Arnab