Microsoft AD Spoke : "Does group exist?" always fails if group doesn't exist

loicthery
Tera Contributor

Hello everybody,

 

We are trying to automate AD group creation using Microsoft AD Spoke V2.

Before to attemp creation, we want to check if group exists.

If group exists, the action "Does group exist?" returns "true" and stops succefully.

If group is missing, the action fails with error "Invalid group name" and flow stops in error.

 

Do you know a way to make it work?

Regards,

Loïc

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi @loicthery 

what about wrapping the call "Does group exists" with a try-catch-block. That way it is not stopping the execution and you can handle the error accordingly.

Maik

View solution in original post

7 REPLIES 7

jmiskey
Kilo Sage

I tried a "Try-Catch" around the "Does Group Exist" Action, but for some reason it is skipping my error, so that catch never runs (see below):

jmiskey_0-1710341357221.png

 

What is going on???

To get the correct behaviour, we copied of the action "Does group exists" and made 2 changes in the step #3 "Post Processing & Error Handling" :

1. Lines 23-29 : we set the output variable and leave the error_message empty

        else if (error_message.indexOf(actionErrors.CANT_FIND_OBJECT) != -1) {
            resource_name = (errMessage.split("' under:"))[0];
            resource_name = (resource_name.split("identity: '")[1]).trim();
            if (resource_name == inputs.group_name) {
                //error_message = "Invalid Group Name : " + resource_name;
                // LTH - 2024-01-16 : If the resource is the expected group, we need to return 'false'
                outputs.does_group_exists = false;
                error_message = "";
            } else
                error_message = errorMessages.INVALID_OBJECT_IDENTITY + " : " + resource_name;

 2. Line 35 : we throw the error only if needed

        // LTH - 2024-01-16 : Throw an error only if the error message is set
        if (JSUtil.notNil(error_message)) {
            throw new Error(error_message);
        }

 We now can expect Service Now developpers will enhance the behaviour quickly.

 

I hope these pieces of code could help 🙂

 

Have a nice coding day,

Loïc

jmiskey
Kilo Sage

So much for low code/no code!

I really wish ServiceNow would clean some of these issues up and get them working properly (as intended), especially since they say they are no longer developing Workflow Editor.