Workflow -- identity search - loop through and send email

looking for guidance on what I’m doing wrong with the workflow.

The workflow is retrieving a list of identities from a search query.
I’m then doing a loop to send an email about each identity.

The email body is not reporting the actual value.

I receive the expected eight emails that match the search query.

below is the output in the email
Debug info: Identity: $.loop.loopInput Name: ${identity.name} Display Name: ${identity.displayName} Username: ${identity.uid} The AD account for ${identity.name} will expire in 7 days. Please extend the expiration date if needed.

{
    "id": "ad4b11b6-8704-4f3a-d1bc",
    "name": "Copy of AD Account Expiration Check and Notification 2",
    "description": "Checks AD account expiration date and notifies manager if within 7 days",
    "created": "2025-06-25T20:51:19.69421315Z",
    "modified": "2025-06-26T00:18:18.746904808Z",
    "modifiedBy": {
        "type": "IDENTITY",
        "id": "dadd5b7a96a084635a",
        "name": "Fred"
    },
    "definition": {
        "start": "Get List of Identities",
        "steps": {
            "End Step - Success": {
                "actionId": "sp:operator-success",
                "displayName": "",
                "type": "success"
            },
            "Get List of Identities": {
                "actionId": "sp:get-identities",
                "attributes": {
                    "inputQuery": "attributes.lcsExpiresin7days:true AND attributes.userType:Non-Employee",
                    "inputSavedSearch": null,
                    "searchBy": "searchQuery"
                },
                "description": null,
                "displayName": "",
                "nextStep": "Loop",
                "type": "action",
                "versionNumber": 2
            },
            "Loop": {
                "actionId": "sp:loop:iterator",
                "attributes": {
                    "context.$": "$.loop.loopInput",
                    "input.$": "$.getListOfIdentities.identities",
                    "start": "Send Email",
                    "steps": {
                        "End Step - Success 1": {
                            "actionId": "sp:operator-success",
                            "displayName": "",
                            "type": "success"
                        },
                        "Send Email": {
                            "actionId": "sp:send-email",
                            "attributes": {
                                "body": "Debug info: \n\nIdentity: ${identity}\n\nName: ${identity.name}\n\nDisplay Name: ${identity.displayName}\n\nUsername: ${identity.uid}\n\nThe AD account for ${identity.name} will expire in 7 days. Please extend the expiration date if needed.",
                                "context": {
                                    "identity": "$.loop.loopInput"
                                },
                                "from": "",
                                "recipientEmailList": [
                                    "[email protected]"
                                ],
                                "replyTo": "",
                                "subject": "AD Account Expiration Notice - Debug"
                            },
                            "displayName": "Send Notification to Manager",
                            "nextStep": "End Step - Success 1",
                            "type": "action",
                            "versionNumber": 2
                        }
                    }
                },
                "displayName": "",
                "nextStep": "End Step - Success",
                "type": "action",
                "versionNumber": 1
            }
        }
    },
    "enabled": false,
    "executionCount": 0,
    "failureCount": 0,
    "creator": {
        "type": "IDENTITY",
        "id": "dadd5b7a96a044635a",
        "name": "name"
    },
    "owner": {
        "type": "IDENTITY",
        "id": "96a0467f8c87f418b484635a",
        "name": "name"
    },
    "trigger": {
        "type": "SCHEDULED",
        "attributes": {
            "cronString": "0 17 * * *",
            "dailyTimes": [
                "1969-12-31T22:00:00.000Z"
            ],
            "frequency": "daily",
            "id": "idn:cron-schedule",
            "timeZone": "EST"
        }
    }
}

Hello,

To be honest, I’m not sure if you can define your loop context directly as loopInput.
However, you can try setting your email context like this:

{
  "identity.$": "$.loop.loopInput.id",
  "displayName.$": "$.loop.loopInput.displayName"
}

What I suggest is placing a Get Identity step inside the loop. This way, you can retrieve the full identity details for each iteration and use them in the email template context. That approach will also allow you to include even more information in the email.

Just keep in mind that workflow loops have a limit of 250 iterations. If your identity search returns more than that, only the first 250 identities will be processed.

Best regards!

thanks, I’ll dive into this more tomorrow. I thought it would only handle 100 iterations and was looking at recursion for handling more if needed. This is handling a NERM use case so the 250 should hopefully be sufficient.

{
    "identity.$": "$.loop.loopInput"
}

worked great, thank you

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.