Automatic Employee Profile Creation does not trigger Business Rules

FelixF
Tera Contributor

Hi!

We have been trying to automate more and more of our SPM, and we have come across a few issues. 
Currently we have tried to automatically set the employee_type for all created employee profiles to Internal. 

A simple business rule was created, that sets the employee_type to Internal as an action, when an employee profile is inserted. 

 

This business rule works, when an employee profile is created manually. However, when the scheduled job that creates employee profiles from user data is used, this business rule no longer works.
the scheduled job that is used is the following one:


Generate Employee Profiles from Users

FelixF_0-1764605048422.png


As mentioned, the business rule is a very simple one, on insert into the sn_employee_profile table, set employee_type to internal. 

Any ideas what could be blocking the business rule from triggering when the scheduled job runs?

Thanks!

1 ACCEPTED SOLUTION

I chased the rabbit and found setWorkflow(false) in the ep_UtilsSNC script on line 114, within an IF statement so that it's only triggered when the createEmployeeProfileFromUser function is called with the second argument = true.  This function is called from the ep_generateEmployeeProfileUtilsSNC script on line 90, with the second argument = true.  So now you have to ask yourself why they did this in the out of box script, but with the override capability.  If you don't find any other Business Rules that would be harmful to run in this situation, you can override the function that this call is in via the ep_generateEmployeeProfileUtil script include.

https://www.servicenow.com/community/developer-forum/how-to-use-function-from-base-script-include-in... 

 

You could also set a default value of internal on the employee type field, only changing it to external when appropriate via manual creation, import, or however any other employee profiles are getting created.

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

Even if you found the culprit deep within the Script Include called by this script, or something it calls, it wouldn't be advisable to try to change it, for the same reason you can't add the code to the script to set the type to internal - modifying an out of box script, and everything that entails.  Have you tried switching the business rule to run after Insert, including a current.update() to save the change?  Are there any Filter Conditions or a Condition on the Advanced tab?

Hi Brad, 

We weren't planning on changing any of the ootb scripts, too risky. But even then I was looking for the culprit in several of the called script includes but could not find what was causing the Business Rule not to trigger. Especially since it only ignores the BR when the automated Scheduled Job is used rather than creating it manually.

I've tried to create the business rule with after insert, with current.update() as well. there are no extra filter conditions either. The idea was, to simply set the employee_type to internal on creation, rather than having to edit it later manually all the time.

I have added logs to the BR as well, and when i use the business rule to trigger on update to the employee profile, it will change the employee_type, it triggers and i can find the logs. but when I use the automated Scheduled job, the BR is not even fired. Even when debugging it doesn't even say, that the BR is skipped, it just doesn't even register in any way.  

I chased the rabbit and found setWorkflow(false) in the ep_UtilsSNC script on line 114, within an IF statement so that it's only triggered when the createEmployeeProfileFromUser function is called with the second argument = true.  This function is called from the ep_generateEmployeeProfileUtilsSNC script on line 90, with the second argument = true.  So now you have to ask yourself why they did this in the out of box script, but with the override capability.  If you don't find any other Business Rules that would be harmful to run in this situation, you can override the function that this call is in via the ep_generateEmployeeProfileUtil script include.

https://www.servicenow.com/community/developer-forum/how-to-use-function-from-base-script-include-in... 

 

You could also set a default value of internal on the employee type field, only changing it to external when appropriate via manual creation, import, or however any other employee profiles are getting created.

This worked. so simple that i didn't think of it. Thank you 🙂