How to check who has viewed the Record.

devservicenow k
Tera Contributor
 
1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @devservicenow k ,

 

Fields:

u_viewedrecord -reference field type on Case/Incident table,

u_username - User reference field type on User table,

u_usertime - Date/Time filed type

 

No need 2 reference fields on case table. u_parent, u_viewedrecord. Use any one of them.

 

Create display business rule on case table. but I tried on Incident table.

Script: 

 

(function executeRule(current, previous /*null when async*/ ) {

var graud = new GlideRecord("u_audit"); //audit table name
graud.initialize();
//graud.u_viewedrecord = current.sys_id; // current.sys_id and getunique value both will work as same.
graud.u_viewedrecord = current.getUniqueValue();
graud.u_username = gs.getUserID(); // to get the user id
graud.u_usertime = new GlideDateTime(); // to get the time that viewed by user
graud.insert();

})(current, previous);

 

Give all your field names that you created on audit  table it will work.

 

Relationship Query:

 

(function refineQuery(current, parent) {

// Add your code here, such as current.addQuery(field, value);
current.addQuery('u_viewedrecord', parent.sys_id);

})(current, parent);

 

Screenshot (197).png

 

Audit records LIST:

Screenshot (198).png

 

Audit Relationship: It will display only parent incident/case related records.

 

Screenshot (200).png

 

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

18 REPLIES 18

shloke04
Kilo Patron

Hi,

Can you explain on the use case here on why you want to track each and every form refresh into a custom table?

What happens say if someone refreshes the form 10 times, which is also opening a form itself then the plan is to record that 10 times into a custom table?

 

Sharing the use case will help to assist better.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Record is viewed without record number

In that case, there are suggestions available on below threads from other experts either to make use of a Display Business Rule or make use of an OOTB event name as "user.view". 

https://www.servicenow.com/community/it-service-management-forum/audit-if-someone-just-opens-a-ticke...

 

Can you share the script of the Display BR which you have tried and also the issue which you are facing?

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

i have tried in BR display, where it stores the name ,time correctly. but the particular record is not getting saved.

 

can you confirm the Field Types for below attributes in your custom table:

1. u_viewedrecord 

2. u_parent 

Are these Reference fields created in your Audit table? In your script you are adding the sys id of the current record to these fields, for that too work then the above fields need to be reference and the reference table should be Case so that when you add the sys id it should get mapped properly.

Add screenshot of your custom table as well how do the fields look like to understand on how have you set up?

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke