{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":823,"path":"api-reference/server-api-reference/HistoryWalkerScopedAPI.md","title":"HistoryWalker - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# HistoryWalker - Scoped, Global\n\nThe HistoryWalker API uses the audit/history tables to generate a historical version of an existing record. This historical version contains all updates to all fields for the specified glide record.\n\nThis API provides the ability to return a GlideRecord to a previous update count \\(walked GlideRecord\\) with the appropriate glide elements populated. After the walked GlideRecord is retrieved, the API provides the ability to move forward and backward between the update numbers, navigating through its historical updates.\n\nThis API enables you to:\n\n-   Instruct the HistoryWalker API to use a specific history walker implementation to retrieve audit data.\n-   Navigate through the historical version of a glide record.\n-   Apply the appropriate history/audit data to get an existing GlideRecord to the state it was in a specific update count.\n-   Turn off row-level access control.\n-   Turn off field-level access control.\n-   Turn off retrieval and processing of \"changes\" data.\n-   Enable journal fields.\n-   Enable variables.\n\nThe HistoryWalker API provides four ways to retrieve audit data:\n\n1.  HISTORY - History walker\n\n    If not available or not up to date, creates a History Set \\[sys\\_history\\_set\\] record for the glide record that you passed when instantiating the HistoryWalker API, using the data in the Sys Audit \\[sys\\_audit\\] table. The sys\\_history\\_set table contains the name of the associated History \\[sys\\_history\\_line\\] table. The sys\\_history\\_line table contains a record for each field value that has been updated in the table being walked. Using this retrieval method, HistoryWalker methods retrieve history data from the generated sys\\_history\\_line table, instead of directly querying the sys\\_audit table.\n\n    The records within the sys\\_history\\_line table are sorted and grouped by ascending Update \\[update\\] field values rather than by chronological order. The update field is loosely associated with the Updates \\[sys\\_mod\\_count\\] field on the task table.\n\n    **Note:** Updates of the sys\\_mod\\_count by clients is not synchronized and therefore can be overwritten, making this count unreliable.\n\n2.  AUDIT - Audit walker\n\n    Queries the sys\\_audit table for the glide record that you passed when instantiating the HistoryWalker API. Each record in the sys\\_audit table contains the changes to field values that occurred through the life of the record.\n\n    Records are sorted ascending by the Update count \\[record\\_checkpoint\\] field rather than by chronological order. The record\\_checkpoint field is loosely associated with the Updates \\[sys\\_mod\\_count\\] field on the task table. One-to-one correlation is not guaranteed.\n\n    Things to consider when deciding whether to use the AUDIT retrieval method:\n\n    -   Size of the sys\\_audit table. The sys\\_audit table can become quite large as the changes for all fields in all records are maintained in this table.\n    -   Possible lack of update zero record depending on the setting of the system property **glide.sys.audit\\_inserts**. This property defines whether an audit record is created with the initial field values when a record is first inserted in a table. In a base system, this property is set to \"false\" causing the HistoryWalker API to do additional processing to account for this missing information.\n    As such, running the HistoryWalker API with AUDIT isn't as performant as either HISTORY or CHECKPOINT.\n\n3.  CHECKPOINT - Checkpoint walker\n\n    Uses a hybrid approach to obtain historical data from the sys\\_history\\_set or sys\\_audit table depending on the setting of the system property **com.glide.history\\_walker.max\\_history\\_count**. If the record to walk has a sys\\_mod\\_count that exceeds the value set in this property, default value = 1,000, the checkpoint walker uses the sys\\_audit table to obtain history data. Otherwise it uses the sys\\_history\\_set table.\n\n    The reason for this check is that the sys\\_history\\_set table provides a more performant approach for walking history data, but only up to a certain point. When the total number of field updates reaches a certain level, approximately 10K, the generation of the sys\\_history\\_set table can exceed the user transaction timeout. If the timeout is exceeded, the overall results are worse in performance than running against the sys\\_audit table that contains all table updates. The checkpoint walker uses the **com.glide.history\\_walker.max\\_history\\_count** to determine the optimal record set to use to achieve the best performance.\n\n    Records are grouped and sorted ascending by the Record Internal Checkpoint \\[internal\\_checkpoint\\] field. Since the internal\\_checkpoint field is a timestamp, the records are in chronological order. In addition, the internal\\_checkpoint field has no association to the task.sys\\_mod\\_count field.\n\n    The most important difference between the checkpoint walker and other walkers is that the other walkers are coupled to and driven by task.sys\\_mod\\_count entries and related to sys\\_audit.record\\_checkpoint and sys\\_history\\_line.update. The checkpoint walker uses the sys\\_audit.internal\\_checkpoint and sys\\_history\\_line.internal\\_checkpoint fields respectively.\n\n    The record internal checkpoint addresses both of these issues making the checkpoint walker the most reliable way to retrieve audit history data.\n\n4.  OFFLINE - Offline history walker\n\n    Provides the offline history feature used by applications such as the Field Service mobile offline app. When a task table extension has fields with the dictionary attribute offline\\_timestamp\\_field set, the offline history walker runs irrespective of any property or explicit instruction to use another walker. The offline history walker uses the sys\\_history\\_line and sys\\_history\\_set tables, which contain history data purposely ordered by date and time, to support offline updates. Only the offline history walker can give accurate results for such tables.\n\n    **Note:** For offline updates, the HistoryWalker API is initiated automatically and the only two methods that you can use are: walkTo\\(0\\) and walkForward\\(\\). You can't call other HistoryWalker methods for offline updates.\n\n\nThe system property **com.snc.walker.default** defines the default type of record walking to perform when instantiating the HistoryWalker API. For upgrading customers, this property is set to \"HISTORY\". For new customers, this property is set to \"CHECKPOINT\".\n\nWhen you instantiate the HistoryWalker API as follows, the **com.snc.walker.default** property determines which record walker implementation the API uses.\n\n```\nvar hw = new sn_hw.HistoryWalker(<table name>, <sys_id>);\n```\n\nYou can also pass the type of record walker to use when instantiating the API. It’s advisable to always include the desired walker implementation when instantiating this API.\n\n```\nvar hw = new sn_hw.HistoryWalker(<table name>, <sys_id>, <walker>);\n```\n\nsuch as:\n\n```\nvar hw = new sn_hw.HistoryWalker('incident', '1c741bd70b2322007518478d83673af3', 'CHECKPOINT');\n```\n\nTo use this class in scoped and global applications, use the `sn_hw` namespace identifier. The History Walker plugin \\(com.glide.history\\_walker\\) that is enabled by default is required to access the HistoryWalker API.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## HistoryWalker - HistoryWalker\\(String tableName, String sysId, String walker\\)\n\nInstantiates the HistoryWalker object and retrieves the historic data for the specified glide record.\n\n<table id=\"table_sdw_1tl_qbb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ntableName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of table that contains the record to retrieve.\n\n</td></tr><tr><td>\n\nsysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the record whose historic data you want to retrieve.\n\n</td></tr><tr><td>\n\nwalker\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Name of the history walker to use to retrieve the historic data for the specified record.Valid values:\n\n-   AUDIT\n-   CHECKPOINT\n-   HISTORY\n-   OFFLINE\n\nDefault: Walker specified in the system property com.snc.walker.default.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method to walk through the changes made to the GlideRecord using the checkpoint walker.\n\n```\n\nvar gr_Hw = new GlideRecord('sc_req_item');\ngr_Hw.get('b0d3335d49534210f877468e89703a7c');\n \nvar hw = new sn_hw.HistoryWalker(gr_Hw.getTableName(), gr_Hw.getUniqueValue(), 'CHECKPOINT');\nhw.walkTo('19096afcc800000001');\nprintChangedFields(hw);\n \nfunction printChangedFields(hw) {\n   var walkedGr = hw.getWalkedRecord();\n   var fields = GlideScriptRecordUtil.get(walkedGr).getChangedFieldNames();\n   gs.info('Fields changed at update ' + hw.getUpdateNumber() + ' were:');\n   for (var j = 0; j < fields.size(); j++) {\n      var fieldName = fields.get(j) + '';\n      if (fieldName !== 'variables')\n         gs.info(walkedGr.getValue('sys_updated_on') + ' ' + fieldName + '=' + walkedGr.getValue(fieldName));\n   }\n \n   var variables = walkedGr.variables;\n   for (var variableName in variables) {\n      if (variables[variableName].changes())\n         gs.info(walkedGr.getValue('sys_updated_on') + ' ' + variableName + '=' + variables[variableName].getValue());\n   }\n   gs.info('');\n}\n```\n\nOutput:\n\n```\nFields changed at update 3 were:\n2024-07-09 08:50:21 price=1499\n2024-07-09 08:50:21 state=2\n2024-07-09 08:50:21 priority=2\n2024-07-09 08:50:21 recurring_price=100\n```\n\n## HistoryWalker - HistoryWalker\\(String tableName, String sysId, Boolean useAudit\\)\n\nFetches the database record based on the parameters, using the History Sets or Audit data to retrieve the historic data, depending on the third parameter.\n\n<table id=\"table_h5d_ycn_qbb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ntableName\n\n</td><td>\n\nString\n\n</td><td>\n\nName of table containing the record to retrieve.\n\n</td></tr><tr><td>\n\nsysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the record to retrieve.\n\n</td></tr><tr><td>\n\nuseAudit\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to use audit data to retrieve historic date.Valid values:\n\n-   true: Use audit data to retrieve historic date.\n-   false: Use history set to retrieve historic date.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue(), true);\nif (hw.walkTo(3)) {\n    var oldPriority = hw.getWalkedRecord().priority;\n    gs.info('Incident priority in update number ' + hw.getUpdateNumber() + ' was ' + oldPriority);\n} else\n    gs.info('Incident does not have update number 3');\n\n```\n\nOutput:\n\n```\nIncident priority in update number 3 was 4\n```\n\n## HistoryWalker - getUpdateNumber\\(\\)\n\nGets the update number of the current walked glide record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|int|Current update number or -1 if record is not found.|\n\nThe following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nfor(int i = 0; i < 2; i++) {\n  hw.walkForward();\n}\ngs.info('Update number: ' + hw.getUpdateNumber());\n```\n\nOutput:\n\n```\nUpdate number: 3\n```\n\n## HistoryWalker - getWalkedRecord\\(\\)\n\nGets the record filled with the history/audit data after walking to an update number.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|The walked GlideRecord.|\n\nThe following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n \nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nhw.walkForward();\nvar walkedRecord = hw.getWalkedRecord();\ngs.info('Priority in update number 0: ' + walkedRecord.priority);\nhw.walkForward();\nwalkedRecord = hw.getWalkedRecord();\ngs.info('Short description in update number 1: ' + walkedRecord.short_description);\n```\n\nOutput:\n\n```\n Priority in update number 0: 4\nShort description in update number 1: My monitor has stopped working\n```\n\n## HistoryWalker - getWalkedRecordCopy\\(\\)\n\nReturns a copy of the record filled with the history/audit data after walking to an update number.\n\n**Note:** The getWalkedRecord\\(\\) method might modify the obtained walkedRecord after walking to another update number. The getWalkedRecordCopy\\(\\) method gets a clone to the walked record to prevent that.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|Copy of the walked GlideRecord.|\n\nThe following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n \nvar walkedRecord = [];\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nhw.walkForward();\nwalkedRecord[0] = hw.getWalkedRecordCopy();\nhw.walkForward();\nwalkedRecord[1] = hw.getWalkedRecordCopy();\n \ngs.info('Priority in update number 0: ' + walkedRecord[0].priority);\ngs.info('Short description in update number 1: ' + walkedRecord[1].short_description);\n```\n\nOutput:\n\n```\nPriority in update number 0: 4\nShort description in update number 1: My monitor has stopped working\n```\n\n## HistoryWalker - isFieldLevelSecurity\\(\\)\n\nSpecifies if the record-level read access is applied on the record when retrieving from the database.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_ycy_1vs_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether field-level security is enabled.Valid values:\n\n-   true: Field-level security is enabled.\n-   false: Field-level security isn't enabled.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\ngs.info('Field level security is active: ' + hw.isFieldLevelSecurity());\n```\n\nOutput:\n\n```\nField level security is active: true\n```\n\n## HistoryWalker - isRecordLevelSecurity\\(\\)\n\nSpecifies if the record-level read access is applied on the record when retrieving from the database.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_prv_jts_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether record-level security is enabled.Valid values:\n\n-   true: Record-level security is enabled.\n-   false: Record-level security isn't enabled.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\ngs.info('Record level security is active: ' + hw.isRecordLevelSecurity());\n\n```\n\nOutput:\n\n```\nRecord level security is active: true\n```\n\n## HistoryWalker - isWithChanges\\(\\)\n\nSpecifies if any of the methods that walk the record from one update to another, support the \"changes\" data for each element.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_zs5_nrs_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether change support is enabled.Valid values:\n\n-   true: Change support is enabled.\n-   false: Change support isn't enabled.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\ngs.info('Changes is active: ' + hw.isWithChanges());\n```\n\nOutput:\n\n```\nChanges is active: true\n```\n\n## HistoryWalker - isWithJournalFields\\(\\)\n\nSpecifies if journal type fields are populated from the historical values.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_smd_1ws_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether journal fields are populated.Valid values:\n\n-   true: Journal fields are populated.\n-   false: Journal fields aren't populated.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\ngs.info('Populating journal fields is active: ' + hw. isWithJournalFields());\n\n```\n\nOutput:\n\n```\nPopulating journal fields is active: false\n```\n\n## HistoryWalker - isWithVariables\\(\\)\n\nSpecifies if values are set for variables that are recorded in the history.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_qhm_jxs_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether values are set for variables that are recorded in the history.Valid values:\n\n-   true: Values are set.\n-   false: Values aren't set.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\ngs.info('Populating variables is active: ' + hw. isWithVariables());\n```\n\nOutput:\n\n```\nPopulating variables is active: false\n```\n\n## HistoryWalker - setFieldLevelSecurity\\(Boolean fieldLevelSecurity\\)\n\nSets the field-level read access on each element before setting the historical value of that element in the GlideRecord. If the field-level security is enabled, it prevents the API from populating the fields of the walked record that the user of the API doesn't have access to.\n\n<table id=\"table_clj_xts_qbb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nfieldLevelSecurity\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates how to set the field-level read access security.Valid values:\n\n-   true: Enable field-level security.\n-   false: Disable field-level security.\n\nDefault: true\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThe following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n \nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nhw.setFieldLevelSecurity(false);\nhw.walkForward();\n```\n\n## HistoryWalker - setRecordLevelSecurity\\(Boolean recordLevelSecurity\\)\n\nSets the record-level read access on the record when retrieving from the database. The record-level security prevents the API from retrieving the walked record if the user of the API doesn't have access to the GlideRecord.\n\n<table id=\"table_trq_kss_qbb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nrecordLevelSecurity\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates how to set the record-level read access security.Valid values:\n\n-   true: Enable record-level security.\n-   false: Disable record-level security.\n\nDefault: true\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThe following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nhw.setRecordLevelSecurity(false);\nhw.walkForward();\n```\n\n## HistoryWalker - setWithChanges\\(Boolean withChanges\\)\n\nSets the \"changes\" data support for each element for a method that walks the record from one update to another.\n\n<table id=\"table_ob3_c2n_qbb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nwithChanges\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the changes data is supported for each element.Valid values:\n\n-   true: Change data is supported for each element.\n-   false: Change data is not supported for each element.\n\nDefault: true\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis code example shows how to call this method with Changes data support. This example must be run in global scope.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nwhile (hw.walkForward()) {\n  printChangedFields(hw);\n}\n\nfunction printChangedFields(hw) {\n  var walkedGr = hw.getWalkedRecord();\n  var fields = GlideScriptRecordUtil.get(walkedGr).getChangedFieldNames();\n  gs.info(\"Fields changed at update \" + hw.getUpdateNumber() + \" were:\");\n  for (var j = 0; j < fields.size(); j++)\n    gs.info(\" \" + fields.get(j));\n  gs.info(\"\");\n}\n```\n\nThis code example shows how to call this method without Changes data support. This example runs in both scoped and global environments.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nhw.setWithChanges(false);\n\nwhile (hw.walkForward()) {\n  var oldPriority = hw.getWalkedRecord().priority;\n  gs.info('Incident priority in update number ' + hw.getUpdateNumber() + ' was ' + oldPriority);\n}\n```\n\n## HistoryWalker - setWithJournalFields\\(Boolean withJournalFields\\)\n\nSpecifies if journal type fields are populated from the historical values.\n\n<table id=\"table_nz1_nvs_qbb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nwithJournalFields\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to include journal-type fields.Valid values:\n\n-   true: Include journal-type fields.\n-   false: Don't include journal-type fields.\n\nDefault: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThe following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nhw.setWithJournalFields(true);\nif (hw.walkForward()) {\n  var workNotes = hw.getWalkedRecord().work_notes;\n  gs.info('Work Notes in update number ' + hw.getUpdateNumber() + ' was ' + workNotes);\n}\n```\n\n## HistoryWalker - setWithVariables\\(Boolean withVariables\\)\n\nSpecifies if variables are populated from the historical values.\n\n<table id=\"table_v4q_rws_qbb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nwithVariables\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether variables are populated from the historical values.Valid values:\n\n-   true: Variable are populated.\n-   false: Variable aren't populated.\n\nDefault: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThe following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nhw.setWithVariables(true);\nhw.walkTo(0);\nif (hw.walkTo(0)) {\n    var varUrgency = hw.getWalkedRecord().variables.urgency;\n    gs.info('Variable Urgency in update number ' + hw.getUpdateNumber() + ' was ' + varUrgency);\n}\n\n```\n\n## HistoryWalker - walkBackward\\(\\)\n\nApplies the appropriate history/audit data to get a walked GlideRecord to the state when it was one update number backward. If the previous update count is missing from the history/audit data, it will walk to the previous available update count.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_sc3_nzs_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether walking to the specified update number was possible.Valid values:\n\n-   true: Able to walk to the specified update number.\n-   false: Unable to walk to the specified update number.\n\nPossible reasons: Already walked to the update number 0.\n\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\n\nwhile (hw.walkBackward()) {\n  var oldPriority = hw.getWalkedRecord().priority;\n  gs.info('Incident priority in update number ' + hw.getUpdateNumber() + ' was ' + oldPriority);\n}\n```\n\nOutput:\n\n```\nIncident priority in update number 5 was 2\nIncident priority in update number 4 was 4\nIncident priority in update number 3 was 4\nIncident priority in update number 2 was 4\nIncident priority in update number 1 was 4\nIncident priority in update number 0 was 4\n\n```\n\n## HistoryWalker - walkForward\\(\\)\n\nApplies the appropriate history/audit data to get a walked GlideRecord to the state when it was one update number forward. If next update count is missing from the history/audit data, it will walk to the next available update count.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_tpm_bzs_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether walking to the specified update number was possible.Valid values:\n\n-   true: Able to walk to the specified update number.\n-   false: Unable to walk to the specified update number.\n\nPossible reasons: Already walked to the GlideRecord update count.\n\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\n\nwhile (hw.walkForward()) {\n  var oldPriority = hw.getWalkedRecord().priority;\n  gs.info('Incident priority in update number ' + hw.getUpdateNumber() + ' was ' + oldPriority);\n}\n```\n\nOutput:\n\n```\nIncident priority in update number 0 was 4\nIncident priority in update number 1 was 4\nIncident priority in update number 2 was 4\nIncident priority in update number 3 was 4\nIncident priority in update number 4 was 4\nIncident priority in update number 5 was 2\n \n```\n\n## HistoryWalker - walkTo\\(int updateCount\\)\n\nApplies the appropriate history/audit data to get a GlideRecord to the state it was in a specific update count. Use getWalkedRecord\\(\\) or getWalkedRecordCopy\\(\\) after walking to an update number to retrieve the \"walked\" GlideRecord.\n\n**Note:** This method is not supported by the checkpoint walker implementation. Call the [HistoryWalker - walkTo\\(String checkpoint\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/HistoryWalkerScopedAPI.md) method when using the checkpoint walker.\n\n|Name|Type|Description|\n|----|----|-----------|\n|updateCount|Integer|Update number to walk to.|\n\n<table id=\"table_qjv_jys_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether walking to the specified update number was possible.Valid values:\n\n-   true: Able to walk to the specified update number.\n-   false: Unable to walk to the specified update number.\n\nPossible reasons: The requested update is greater than the update count of the GlideRecord or there is no history/audit data for the requested update number.\n\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method.\n\n```\nvar incGr = new GlideRecord('incident');\nincGr.get('number', 'INC0000015');\n\nvar hw = new sn_hw.HistoryWalker(incGr.getTableName(), incGr.getUniqueValue());\nif (hw.walkTo(3)) {\n    var oldPriority = hw.getWalkedRecord().priority;\n    gs.info('Incident priority in update number ' + hw.getUpdateNumber() + ' was ' + oldPriority);\n} else\n    gs.info('Incident does not have update number 3');\n```\n\nOutput:\n\n```\nIncident priority in update number 3 was 4\n```\n\n## HistoryWalker - walkTo\\(String checkpoint\\)\n\nApplies the appropriate history/audit data to get a GlideRecord to the state it was in for a specific record internal checkpoint. Use the getWalkedRecord\\(\\) or getWalkedRecordCopy\\(\\) method after walking to a record's internal checkpoint to retrieve the \"walked\" GlideRecord.\n\n**Note:** This method is only supported by the checkpoint walker implementation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|checkpoint|String|Record's internal checkpoint to walk to. You can find this value in the internal\\_checkpoint field of the Sys Audit \\[sys\\_audit\\] or History \\[sys\\_history\\_line\\] table.|\n\n<table id=\"table_qjv_jys_qbb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether walking to the specified record's internal checkpoint was possible.Possible values:\n\n-   true: Able to walk to the specified record's internal checkpoint.\n-   false: Unable to walk to the specified record's internal checkpoint.\n\nPossible reasons: The internal checkpoint doesn't exist.\n\n\n</td></tr></tbody>\n</table>The following code example shows how to call this method to walk through the changes made to the GlideRecord.\n\n```\n\nvar gr_Hw = new GlideRecord('sc_req_item');\ngr_Hw.get('b0d3335d49534210f877468e89703a7c');\n \nvar hw = new sn_hw.HistoryWalker(gr_Hw.getTableName(), gr_Hw.getUniqueValue(), 'CHECKPOINT');\nhw.walkTo('19096afcc800000001');\nprintChangedFields(hw);\n \nfunction printChangedFields(hw) {\n   var walkedGr = hw.getWalkedRecord();\n   var fields = GlideScriptRecordUtil.get(walkedGr).getChangedFieldNames();\n   gs.info('Fields changed at update ' + hw.getUpdateNumber() + ' were:');\n   for (var j = 0; j < fields.size(); j++) {\n      var fieldName = fields.get(j) + '';\n      if (fieldName !== 'variables')\n         gs.info(walkedGr.getValue('sys_updated_on') + ' ' + fieldName + '=' + walkedGr.getValue(fieldName));\n   }\n \n   var variables = walkedGr.variables;\n   for (var variableName in variables) {\n      if (variables[variableName].changes())\n         gs.info(walkedGr.getValue('sys_updated_on') + ' ' + variableName + '=' + variables[variableName].getValue());\n   }\n   gs.info('');\n}\n```\n\nOutput:\n\n```\nFields changed at update 3 were:\n2024-07-09 08:50:21 price=1499\n2024-07-09 08:50:21 state=2\n2024-07-09 08:50:21 priority=2\n2024-07-09 08:50:21 recurring_price=100\n```\n\n"}}