Querying Activities using REST API

kcwong
Tera Contributor

I'm trying to use REST API to pull data from ServiceNow, particularly the data shown in Activities section for the incidents/changes/requests I have. I'm using the table API (/api/now/v1/table/:table_name?sysparm_query=xxx) to find and retrieve data.

So far I've identified:

 

sys_journal_field. This contains work notes/comments/approval history. element = comments|work_notes|approval_history, element_id=master record's sys_id

 
sys_audit. This contains the audit trace. tablename, documentkey, newvalue, oldvalue are the key attributes.
 
sys_email. This contains the email received/sent entries. target_table points to the master record table, while instance.value in the JSON points to the master record. 

Questions: 
1. Are there more types of activities I do not know about? Where can I find documentation for them?
2. How do you use sysparm_query to search a nested JSON value, like for sys_email's instance.value? 
3. How is email stored in sys_email if there are attachments? Because of question 2, I am unable to locate an example in my ServiceNow instance.
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@kcwong 

what's your business requirement?

you should not use OOTB Table API to get details as it exposes all the fields

Instead you can use scripted REST API

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Tanushree Maiti
Tera Patron

Hi @kcwong 

 

When I have been working on e-bonding projects, I created scripted Rest API and using script retrieved the  Journal field values.

 

Try with this: 

https://www.servicenow.com/community/developer-forum/scripted-rest-api-to-retrieve-work-notes-of-an-...

Retrieve journal entries using direct web services 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankur Bawiskar
Tera Patron

@kcwong 

what's your business requirement?

you should not use OOTB Table API to get details as it exposes all the fields

Instead you can use scripted REST API

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Migrating data out of ServiceNow. The records and attachments are done, just need to get all the available data displayed in the Activities section. 

@kcwong 

yes mostly these tables are involved

sys_journal_field

sys_audit

sys_email

I will recommend using Scripted REST API and then use GlideRecord to return the data in whatever format 3rd party wants

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader