GlideRecord query not returning results from HR Case Benefits table

Roberto Cortina
Tera Contributor

Hi everyone,

 

I have an HR Case that after being approved manually with Glide Record by setting the approval to "approved". After the approval I execute another GlideRecord query to get the all the approved (state Closed Complete) HR Cases from an specific HR Service but the problem is that the query is not returning any results. I already checked it and the query seems correct. This query is being executed by using a Script Include. If I execute the same code using the Background Scripts module in ServiceNow I get results. It seems this problem happens only after the approval and when I use the query withing my Script Include. Do you know why is this happening? Could it be a scope application issue? I don't get any errors I just get zero row count. There aren't any conflicting business rules as far as I know.

 

Thanks!

1 ACCEPTED SOLUTION

Kartik Magadum
Kilo Sage

Hello @Roberto Cortina 

 

The issue you're facing with your GlideRecord query not returning any results after the HR Case approval when executed within a Script Include in ServiceNow could be related to a few factors. While it's challenging to pinpoint the exact cause without the code and configurations, here are some common troubleshooting steps you can take:

1. **Scope Issue**: Scope-related issues are a common cause of problems in ServiceNow. Make sure that your Script Include has the correct scope permissions to access the HR Cases and the specific HR Service table. If the code works in the Background Scripts module but not in your Script Include, scope permissions might be the issue.

2. **Transaction Scope**: Verify that your GlideRecord query is not being executed within a different transaction or under different user permissions after the HR Case approval. It's possible that the approval process changes the transaction context or user permissions.

3. **Order of Execution**: Check if there are any business rules or other scripts that are triggered during the HR Case approval process that could affect the data or the behavior of your GlideRecord query. Sometimes, approvals can trigger additional scripts that you might not be aware of.

4. **Query Logic**: Double-check your query logic to ensure that it accurately reflects your criteria. Ensure that the state is correctly set to "Closed Complete" and that the HR Service is properly specified.

5. **Script Include Dependencies**: Make sure that your Script Include doesn't depend on any global variables or configurations that might be different when executed in different contexts. Ensure that any required dependencies are available and correctly initialized.

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Thanks & Regards,

Kartik Magadum

View solution in original post

3 REPLIES 3

Aman Kumar S
Kilo Patron

Hi @Roberto Cortina 

I would suggest checking if the script include and the configuration from which the script include is called are in different scopes, if that's the case, you might have to set Accessible from field to All Application scopes for the script include, in order to be called from different application scope.

 

Best Regards
Aman Kumar

Kartik Magadum
Kilo Sage

Hello @Roberto Cortina 

 

The issue you're facing with your GlideRecord query not returning any results after the HR Case approval when executed within a Script Include in ServiceNow could be related to a few factors. While it's challenging to pinpoint the exact cause without the code and configurations, here are some common troubleshooting steps you can take:

1. **Scope Issue**: Scope-related issues are a common cause of problems in ServiceNow. Make sure that your Script Include has the correct scope permissions to access the HR Cases and the specific HR Service table. If the code works in the Background Scripts module but not in your Script Include, scope permissions might be the issue.

2. **Transaction Scope**: Verify that your GlideRecord query is not being executed within a different transaction or under different user permissions after the HR Case approval. It's possible that the approval process changes the transaction context or user permissions.

3. **Order of Execution**: Check if there are any business rules or other scripts that are triggered during the HR Case approval process that could affect the data or the behavior of your GlideRecord query. Sometimes, approvals can trigger additional scripts that you might not be aware of.

4. **Query Logic**: Double-check your query logic to ensure that it accurately reflects your criteria. Ensure that the state is correctly set to "Closed Complete" and that the HR Service is properly specified.

5. **Script Include Dependencies**: Make sure that your Script Include doesn't depend on any global variables or configurations that might be different when executed in different contexts. Ensure that any required dependencies are available and correctly initialized.

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Thanks & Regards,

Kartik Magadum

Thanks! Very handful information 🙂