How to get previous value of particular field for bulk amount of records using script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2018 05:43 AM
I need to get previous value of fields for bulk amount of records in a table using background script.
For example, I want previous value of (managed by) field in cmdb_ci table for some 500+ records.
I tried using audit table to get previous value....and also that query works but I can't get any values for the records which are updated last month....so will the audit table restore every 30 days ?
Is there any other method to get previous value of record using script other than audit table ?
- Labels:
-
Service Level Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2018 05:56 AM
Hi,
To get the previous value you can script:
var fieldprev = previous.FIELDNAMEHERE.getDisplayValue();
You haven't said what you want to do with it once you get it, but that's how you could get it and store it as a variable. And with that of course you'd need to be within your table that you're wanting. But you've let out details like...are you only wanting those updated last month? Life time? Want it just printed on the screen so you can copy/paste the results? etc...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2018 10:39 PM
Thanks for the reply Allen.
How can I use the below code in scripts-background because we can use previous object in only business rule right ?
var fieldprev = previous.FIELDNAMEHERE.getDisplayValue();
I want previous value for the following reason,
For example, I need to update managed_by field of cmdb_ci table with its previous value for the records having managed_by with value preethi, because due to some reasons those cmdb_ci records were wrongly updated with value preethi. So now I need to correct it with previous value using script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2018 06:04 AM
Please refer below link for more info about audit tables.
https://docs.servicenow.com/bundle/jakarta-platform-administration/page/administer/time/concept/audited-tables-2.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2018 10:39 PM
Thanks for the reply Jayantha.
Will check the document.