Display error message on change record when user click the revert to new button more than 3 times

maheshch18
Tera Contributor

Hi Team,

 

Display error message on change record when the user click the revert to new button more than 3 times with in the month.

 

Regards,

Mahesh.

2 REPLIES 2

Neetu1999
Tera Contributor

Hello @maheshch18 
In servicenow I think we have client script and ui policy for form changes so your requirement is tricky .
You can write a BR on insert and update so whenever the button will click from revert to new increase the flag by one and when flag == 3 then write error msg 
try this way if possible also check at server side do we have any field which stores value in such way that we can figure out how can we get count 

Amarjeet Pal
Kilo Sage
Kilo Sage

Hello @maheshch18 ,

 

  1. Define a display business rules on 'update'.

  2. Advanced condition: Your condition could be something like current.state == New

  3. Scripting: In the script section, you would add code that checks how many times this particular change has been reverted to new within the last month.

Please note: For counting how many times it's been reverted, you may need to maintain an additional custom field or use an audit log depending on your instance's setup.

  1. If the count exceeds 3 times in one month, display an error message like so:
gs.addErrorMessage('You have clicked "Revert to New" more than three times this month.');
current.setAbortAction(true);  

 You can explore sys_audit table and create a query 

var grAudit = new GlideRecord('sys_audit');

// specify your query conditions
grAudit.addQuery('tablename', 'Change_request');
grAudit.addQuery('fieldname', 'state');
grAudit.addQuery('newvalue', 'New'); 
grAudit.addQuery('documentkey', current.sys_id);
grAudit.addQuery('sys_created_on', '>=', oneMonthAgo.getDisplayValue());

// execute the query
grAudit.query();

// count the number of matching records
var revertCount = grAudit.getRowCount();

if(revertCount > 3) {

Display error message as shown above

}