- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 09:38 AM
I created a business rule to updated a created by username. It is very simple but only runs on update and created. Is there away to make it go back an update all cases? Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 09:47 AM
Hi Brandon - You can't run a business rule retroactively, but you could run either a scheduled job to determine which records need updating and then do the update, or you could run a fix script to do similar.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 10:51 AM
You would want to query the table in question to get only those records you want to update, then for each of those records apply your business rule logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 12:35 PM
I tried this code, do you know why it didnt work? I told it to grab cases that are active. I want it to update the field called "created by (display name)"... it did nothing though.
var rec = new GlideRecord('case');
rec.query();
while (rec.next()) {
rec.active = false;
rec.update ('createdbydisplayname)');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 03:28 AM
Hi Brandon - I'm not familiar with the case tables, but I suspect "case" isn't the actual name of the table, but just the display name. You can usually tell the "real" table name when looking at a list of the records by looking at your URL. It will have something like: "/nav_to.do?uri=%2Fchange_request_list.do" >> where change_request is the table name I'm looking at.
So, assuming your table name is case (check the URL when looking at a list of cases), and your goal is to set the Created By field to the Name field of the User table for every record in the case table, you would do something like the following. (This is completely untested, since I don't have access to the case table in my environment)
//get all the case table records where the case is still active
var caseRec = new GlideRecord('case');
caseRec.addQuery('active', 'true');
caseRec.query();
while (caseRec.next()) {
//foreach case, find the user record where the User ID matches the Created By on the case
var userRec = new GlideRecord('sys_user');
userRec.addQuery('user_name', caseRec.sys_created_by);
userRec.query();
if (userRec.next()) {
//set the created by field on the case = the name field of the User
caseRec.sys_created_by=userRec.name;
caseRec.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 11:02 AM
Ah, so a custom code. I am not a coder, nor do we have one on staff. I am more of an admin and was trying to fix it from the business rule side. I think you have the right answer, I just need to learn to right that script lol.