Microsoft Active Directory v2 Spoke Action: Does User Exists (does_user_exists_v2) not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited an hour ago
Is anyone successfully using the "Does User Exists (does_user_exists_v2)" spoke action in the Microsoft Active Directory v2 Spoke?
It seems to work perfectly so long as the user does exist, returning an output value of true and no errors.
But if the user does not exist in AD, the script doesn't simply return an output value of false, as expected, it throws an error and bombs.
Ultimately, I'm trying to invoke the spoke action from a Run Server Side ATF Test step, but it fails even when using the Test button inside Flow Designer, so I think there's an issue with the behavior of the Flow Action itself.
Test 1: User Name DOES exist in AD
- From Flow Designer, open the Does User Exists spoke action and click the Test button
- Enter a User Name that is known to exist in AD, then click Run Test
- Click the "Your test has finished running. View the Action execution details." link
- In the Execution Details page, note the Test Run's State=Completed and the Output Data shows: Action Status = {"Action Status":{"code":0,"message":"Success"}}
Test 2: User Name DOES NOT exist in AD
- From Flow Designer, open the Does User Exists spoke action and click the Test button
- Enter a User Name that is known to NOT exist in AD (e.g. "gobbleDeeBlah"), then click Run Test
- Click the "Your test has finished running. View the Action execution details." link
- In the Execution Details page, note the Test Run's State=Completed (error skipped) and the Output Data shows:
Action Status = {"Action Status": {"code": 1,"message": "Error: Invalid User Name : invalidUserName (Process Automation.f001d66e1b16cf90ae6aa794604bcb8e; line 35)"}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
40m ago
@Joe Walters
This behavior is coming from the OOTB Microsoft Active Directory v2 spoke action.
The “Does User Exists” action is intended to check whether a user exists, but in this case the action’s Post Processing & Error Handling script treats “user not found” as an error and executes:
throw new Error(error_message);
That is why:
Existing AD user → action succeeds and returns true.
Non-existing AD user → instead of returning false, the action status becomes an error such as “Invalid User Name”.
ServiceNow documents “Does User Exists” as an action that checks whether a user account exists in AD, so logically a non-existing user should be handled as a valid negative result rather than an unexpected integration failure. (ServiceNow)
Recommended solution:
Do not modify the OOTB spoke action directly.
Create a custom Action or Subflow that calls “Does User Exists” and handles the result.
For example:
Call the OOTB “Does User Exists” action.
If the action completes successfully and the user exists, return:
User Exists = trueIf the returned error is “Invalid User Name”, treat that as:
User Exists = falseOnly throw an error for actual failures such as:
Authentication failure
MID Server unavailable
Connection failure
PowerShell/AD execution failure
If you have to modify a copied version of the action, change the error handling logic so “Invalid User Name” does not reach:
throw new Error(error_message);
Instead, handle it separately, for example:
if (error_message.indexOf('Invalid User Name') != -1) {
outputs.user_exists = false;
return;
}
throw new Error(error_message);
For your ATF use case, call this custom wrapper action instead of calling does_user_exists_v2 directly. This allows the ATF step to receive false when the AD user does not exist rather than failing the test.
Also check the installed Microsoft Active Directory v2 Spoke version before customizing. ServiceNow currently documents v2.5.2 as the latest version, so if your instance has an older version, upgrade/test the latest spoke first in a non-production instance.