How to get the number of records in a Script Include for even records not available to users?

jpcb0108
Tera Contributor

Hi All,

 

Currently working on a record producer for an HR Service and the request was that if for example person A submits the record producer with a specific subject person (let's say person C), if Person B tries to submit a record producer with the same subject person (person C), he should be stopped and an error message will be displayed. This record producer is being submitted via the portal and Person A & B do not have any of the HR roles just that they are allowed to submit the record producer.

 

So we went ahead and created a GlideAjax + ScriptInclude to hopefully query if there are any tickets opened for the specific subject person once selected on the form. However, we noticed that since they can only see the HR Case tickets that they opened, the GlideAjax + ScriptInclude does not return the actual count of the number of cases opened for the selected subject person. In the sample above, Person B can still submit the form and is not stopped. But of course when person B tries to submit a 2nd time, since he already created 1 case, he gets stopped properly.

 

How best could we approach this to ensure that if a specific subject person has an active Case already open with a specific HR Service that if anyone else tries to do the same, they will be properly stopped.

3 REPLIES 3

kaustubhdub
Tera Expert

hi @jpcb0108 

This behavior is expected. GlideAjax and Script Includes execute in the user’s security context, so users without HR roles can only query HR cases they created themselves. Because of this, client-side validation cannot reliably enforce uniqueness for HR cases.

The correct way to solve this is to move the validation to the server side.

Create a Before Insert Business Rule on the HR Case table (sn_hr_core_case) that checks whether an active case already exists for the same Subject Person and HR Service. Business Rules execute on the server and are not limited by portal visibility.

 

If my solution was helpful, please mark it helpful as this help others find the solution😊

Hi @kaustubhdub ,

 

This is actually for a Lifecycle Event / Journey HR case. We would want to stop users from submitting. I tried using a Before Insert rule (just for testing) but it still does not seem to function as expected when I try to trigger it with the persons without the HR roles it still doesn't return the expected result but with people who have LE Reader role they do see the info message that there is a record already. We want to alert the user that a case has already been raised for the person and to stop the journey, hr  case, etc. from being created. Would you have any other idea on how to go about it.

Ankur Bawiskar
Tera Patron

@jpcb0108 

share your scripts here

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