Looking for the following tables that will show state values and latest ticket update

ktmbdev
Giga Contributor

Hi,

I am using the Rest API Explorer to find the values for State and the latest ticket update (Activities). 

 

The State values within the incident table are all numbers. Also dont see the latest update on the ticket using the same incident table.

1 ACCEPTED SOLUTION

sourav1999
Mega Guru

Sure, I can help you with that. Here are the steps you need to follow:

1. State Values: The state values in the incident table are stored as integers. However, they correspond to different states like New, In Progress, Resolved, etc. Here is a general mapping:
- 1: New
- 2: In Progress
- 3: On Hold
- 4: Resolved
- 5: Closed
- 6: Canceled
- 7: Awaiting Problem
- 8: Awaiting User Info
- 9: Awaiting Evidence
- 10: Awaiting Vendor
- 11: Resolved by Caller

2. **Latest Update on Ticket**: The latest update on a ticket is not directly available in the incident table. You need to use the sys_audit table to get this information. The sys_audit table stores all the changes made to a record.

Here is a sample code to get the latest update on a ticket using REST API:

javascript
var gr = new GlideRecord('sys_audit');
gr.addQuery('documentkey', 'INCIDENT_NUMBER'); // replace INCIDENT_NUMBER with the actual incident number
gr.orderByDesc('sys_created_on');
gr.query();
if (gr.next()) {
gs.info('Latest update: ' + gr.getValue('newvalue'));
}


Replace 'INCIDENT_NUMBER' with the actual incident number you are interested in. This will give you the latest update made on the ticket.

Remember to replace 'newvalue' with the actual field name you are interested in. For example, if you want to know the latest update made on the state field, replace 'newvalue' with 'state'.

 

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai

View solution in original post

1 REPLY 1

sourav1999
Mega Guru

Sure, I can help you with that. Here are the steps you need to follow:

1. State Values: The state values in the incident table are stored as integers. However, they correspond to different states like New, In Progress, Resolved, etc. Here is a general mapping:
- 1: New
- 2: In Progress
- 3: On Hold
- 4: Resolved
- 5: Closed
- 6: Canceled
- 7: Awaiting Problem
- 8: Awaiting User Info
- 9: Awaiting Evidence
- 10: Awaiting Vendor
- 11: Resolved by Caller

2. **Latest Update on Ticket**: The latest update on a ticket is not directly available in the incident table. You need to use the sys_audit table to get this information. The sys_audit table stores all the changes made to a record.

Here is a sample code to get the latest update on a ticket using REST API:

javascript
var gr = new GlideRecord('sys_audit');
gr.addQuery('documentkey', 'INCIDENT_NUMBER'); // replace INCIDENT_NUMBER with the actual incident number
gr.orderByDesc('sys_created_on');
gr.query();
if (gr.next()) {
gs.info('Latest update: ' + gr.getValue('newvalue'));
}


Replace 'INCIDENT_NUMBER' with the actual incident number you are interested in. This will give you the latest update made on the ticket.

Remember to replace 'newvalue' with the actual field name you are interested in. For example, if you want to know the latest update made on the state field, replace 'newvalue' with 'state'.

 

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai