- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 11:08 AM
Is there a specific code or any automation process to track and retrieve the initial description and all the changes made to a short description of incident
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 09:03 PM
Hi Vikram,
There is an api in ServiceNow History Walker newly implemented in ServiceNow to check the initial changes of fields.
var current = new GlideRecord("incident");
if (current. get ("12ca184735123002728660c4cf6a7ef")) {
var hw = new sn_hw. HistoryWalker (current. getTableName (), current . getUniquevalue ()) ;
hw.walkTo(0);
var shortDesc = hw. getwalkedRecord() . short_description;
gs.info('Incident short description in update number ' + hw. getUpdateNumber () + ' was ' + shortDesc);
while (hw.walkForward())
Try above script in background script.
Please mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 09:03 PM
Hi Vikram,
There is an api in ServiceNow History Walker newly implemented in ServiceNow to check the initial changes of fields.
var current = new GlideRecord("incident");
if (current. get ("12ca184735123002728660c4cf6a7ef")) {
var hw = new sn_hw. HistoryWalker (current. getTableName (), current . getUniquevalue ()) ;
hw.walkTo(0);
var shortDesc = hw. getwalkedRecord() . short_description;
gs.info('Incident short description in update number ' + hw. getUpdateNumber () + ' was ' + shortDesc);
while (hw.walkForward())
Try above script in background script.
Please mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 09:09 PM
You can also query the log table to get historical data for short description
var initialShortDescription = '';
var changes = [];
var gr = new GlideRecord('sys_audit');
gr.addQuery('tablename', 'incident');
gr.addQuery('documentkey', current.incident.sys_id);
gr.addQuery('fieldname', 'short_description');
gr.orderBy('sys_created_on');
gr.query();
while (gr.next()) {
if (initialShortDescription === '') {
initialShortDescription = gr.oldvalue;
}
changes.push({
timestamp: gr.sys_created_on.getDisplayValue(),
description: gr.newvalue
});
}
current.short_description= 'Initial: ' + initialShortDescription + '\n';
for (var i = 0; i < changes.length; i++) {
current.short_description_history += changes[i].timestamp + ': ' + changes[i].description + '\n';
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 09:11 PM
You can also try creating a metric for short_deacription field in incident table. This way you can have all the values that were there in the field in the entire life cycle of Incident ticket.
Let me know, If you need more help in this approach.
Please mark my answer helpful and accept as solution if it helped you 👍✅
Anvesh