Display business Rule

edwardwong
Tera Contributor

How can you make a counter that count the number of time a page have been view or visited, I thought that we can use a on-load client script but some people tell me to do display business rule. I been trying with both but I can't seem to make it increase when I visit the page only when I save the form was it able to increase the counter.

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage
Mega Sage

@edwardwong 

Create a new field [Counter] on the table of type integer.

Create a display business rule and add below script

 

current.<COUNTER FIELD NAME> += 1;
current.update();
 
Please mark as correct answer if this solves your issue.
 
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

2 REPLIES 2

jaheerhattiwale
Mega Sage
Mega Sage

@edwardwong 

Create a new field [Counter] on the table of type integer.

Create a display business rule and add below script

 

current.<COUNTER FIELD NAME> += 1;
current.update();
 
Please mark as correct answer if this solves your issue.
 
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @edwardwong 

Do you want to make it generic for overall users or based upon the users ?

If you have any field to store that number then you can do something like below for all the users :-

Display Business Rule :-

 

// Set the number of times the record has been opened to 0
current.u_num_opened = 0;

// Increment the number of times the record has been opened by 1
current.u_num_opened += 1;

// Update the record with the new value
current.update();


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy