How can I declare variables from an HTTP response for a compare strings operator

Hello developer community,

I have been working on enhancing a termination workflow to check for an existing termination ticket in our ITSM and if one does not exist to create one for them.

Limitations/caveats:

  • The ITSM API only allows me to perform a search based on the ticket offering (Termination Request), ticket status (Open,Pending,Submitted), the submitter/affected user(manager), and date logged(no way to dynamically get dates in the workflows yet.).
    *Manager may have multiple termination request submitted for different staff.

My Ask:
How can I take the response below and do a compare on it to ensure there is or is not an existing ticket for john smith in this case? In my example two tickets were returned for the same manager for two different users. I’m assuming the way I am declaring the variable in not proper syntax due to the structure of the response.

Response from ITSM:

    {
    "checkForExistingTerminationRequest": {
        "body": [
            {
                "affectedUserEmail": "Manager email",
                "affectedUserName": "Manager First and last name",
                "customFields": [
                    {
                        "contactUserValue": {
                            "email": "[email protected]",
                            "emailAddress": "[email protected]",
                            "name": "James Walker",
                            "username": "Username"
                        },
                        "customFieldShortCode": "TERMINATED USER",
                        "systemLookupValue": {
                            "email": "[email protected]",
                            "emailAddress": "[email protected]",
                            "name": "James Walker",
                            "shortCode": "jamesusername"
                        },
                        "systemLookupValueShortCode": "jamesusername"
                    }
                ],
                "createddate": "2023-04-20T14:18:09.117-05:00",
                "ticketstatus": "OPEN"
            },
            {
                "affectedUserEmail": "Manager email",
                "affectedUserName": "Manager First and last name",
                "customFields": [
                    {
                        "contactUserValue": {
                            "email": "[email protected]",
                            "emailAddress": "[email protected]",
                            "name": "John Smith",
                            "username": "Username"
                        },
                        "customFieldShortCode": "TERMINATED USER",
                        "systemLookupValue": {
                            "email": "[email protected]",
                            "emailAddress": "[email protected]",
                            "name": "John Smith",
                            "shortCode": "Johnusername"
                        },
                        "systemLookupValueShortCode": "johnusername"
                    }
                ],
                "createddate": "2023-04-13T14:18:09.117-05:00",
                "ticketstatus": "OPEN"
            }
        ],
        "headers": {},
        "responseTime": "1.335754 seconds",
        "statusCode": 200
    }
}

What I have attempted:

  • Using Compare Strings to evaluate $.checkForExistingTerminationRequest.body.customFields.systemLookupValueShortCode Equals $.getIdentity.username

  • Using Compare Strings to evaluate
    $.checkForExistingTerminationRequest.body.customFields.systemLookupValueShortCode Contains $.getIdentity.username

  • Using Verify Data Type
    Verify that $.checkForExistingTerminationRequest.body Exists
    (Verify Data Type sort of works but falls down if there are multiple tickets for employees that are not the one terminating)

I don’t think what you’re trying to do is possible with the current set of capabilities in workflows.

You can’t use the Compare Strings operator since it only compares two string values. It can’t check for the existence of a string within an array.

You also can’t use JSONpath, since you can’t insert a variable into the JSONpath expression to check for the existence of some string based on a previous variable.

I will bring this use case to the Workflow team to get their thoughts on this.

Thanks for the response, Colin.

My alternative was to somehow get the value into a variable and do it that wait but I’m not sure the data structure would allow for that, even with a loop to break up the tickets returned.

Here’s hoping the workflow folks can think of something clever.

The Workflow team now has a ticket in their backlog to support this. I don’t have an ETA, but I can report back here once it is implemented.

1 Like

I appreciate your effort.