Using sys_user_has_role table as a created record trigger in Flow

Brady Gordish
Kilo Contributor

Hello, I've been asked to find a way to send an automated "welcome" email, with KB articles to a user who has been granted the ITIL role. 

I've been trying to do this, through Flow Designer, by setting the trigger to fire every time a new record is created in sys_user_has_role that has a role of itil. 

So far the flow technically works, but not the way we're wanting. If one were to manually assign the role to a users record, the email fires as intended. This does not work, however, if the role is granted as an inherited role from a group. 

From what I can tell, so long as the inheritance count is empty on the record, it works. If there is any number on the inheritance count, the flow simply does not trigger at all.

Would anyone here happen to have an idea as to why this would be happening and know a way to have a flow trigger when someone inherits the itil role for the FIRST time (last thing I want is for my flow to trigger every single time a user record's inheritance count increases)?

 

Note: I had also tried setting the condition of the trigger to also include inheritance count is 1, and having it look for both updated and created records. No dice.

1 ACCEPTED SOLUTION

Well...you could always deactivate that plugin and set up your security to prevent duplicate roles and increase inheritance count, if this is that important.

Otherwise, yes, you'd have to go another way.

You could possibly do a scheduled job for the end of each day to scan and see if any user had ITIL added today (created on today) and then send your ITIL welcome email.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

10 REPLIES 10

And for that a Flow running to a schedule would be perfect.   You would get potentially a list of records returned and then drop into a for each loop to process them 🙂  

Precisely. Glad you found it Helpful and logical as well.

Take care!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

peter_z
ServiceNow Employee
ServiceNow Employee

Interesting.    How are you adding the role to the user?   By adding the "Group" containing the ITL role or adding the itil role directly to the sys_user record please?   And are you using the system user to execute the flow or the user that triggers the insert please?

I did a quick mock up and the Flow is triggered on sys_user_has_role when I add the itil role to the user account,  but not if I add the Change Management group to the user record (which contains the itil role OOTB).

peter_z
ServiceNow Employee
ServiceNow Employee

OK,  so digging around a bit more.    I find the same behaviour with an on insert BR on sys_user_has_role.    Add a group to the user BR doesn't fire.   Add role to the user and the BR fires.

So I dont know how you'd achieve the goal right now as there's no "simple" trigger for this it seems.  

Its an interesting issue,   I'll ask around some more on it.

peter_z
ServiceNow Employee
ServiceNow Employee

A colleague of mine found this thread that is along these same lines.   https://community.servicenow.com/community?id=community_question&sys_id=db00c37adb9097044816f3231f96...

It may be something done by design and if BRs aren't firing when the role is added as part of the group,  then its probable that Flows wont run either.

Not an answer,  but maybe a little helpful.