# Workflow -- identity search - loop through and send email

**URL:** <https://developer.sailpoint.com/discuss/t/workflow-identity-search-loop-through-and-send-email/148424>\
**Category:** SHF Discussion and Questions\
**Tags:** workflows, sailpoint-identity-security\
**Created:** [June 26, 2025, 12:29am UTC](https://developer.sailpoint.com/discuss/t/workflow-identity-search-loop-through-and-send-email/148424 "2025-06-26T00:29:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ts\_fpatterson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ts_fpatterson/32/26704_2.png) [@ts\_fpatterson](https://developer.sailpoint.com/discuss/u/ts_fpatterson)\
**Post date:** [June 26, 2025, 12:29am UTC](https://developer.sailpoint.com/discuss/t/workflow-identity-search-loop-through-and-send-email/148424/1 "2025-06-26T00:29:26Z")

</div>

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.

```auto
{
    "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": [
                                    "fred@example.com"
                                ],
                                "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"
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![YanCoelho](https://avatars.discourse-cdn.com/v4/letter/y/f6c823/32.png) [@YanCoelho](https://developer.sailpoint.com/discuss/u/YanCoelho)\
**Post date:** [June 26, 2025, 1:20am UTC](https://developer.sailpoint.com/discuss/t/workflow-identity-search-loop-through-and-send-email/148424/2 "2025-06-26T01:20:39Z")

</div>

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:

```auto
{
  "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!

---

<div class="post-metadata">

**Author:** ![ts\_fpatterson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ts_fpatterson/32/26704_2.png) [@ts\_fpatterson](https://developer.sailpoint.com/discuss/u/ts_fpatterson)\
**Post date:** [June 26, 2025, 2:38am UTC](https://developer.sailpoint.com/discuss/t/workflow-identity-search-loop-through-and-send-email/148424/3 "2025-06-26T02:38:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ts\_fpatterson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ts_fpatterson/32/26704_2.png) [@ts\_fpatterson](https://developer.sailpoint.com/discuss/u/ts_fpatterson)\
**Post date:** [June 26, 2025, 1:02pm UTC](https://developer.sailpoint.com/discuss/t/workflow-identity-search-loop-through-and-send-email/148424/4 "2025-06-26T13:02:57Z")

</div>

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

```

worked great, thank you

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [August 25, 2025, 1:03pm UTC](https://developer.sailpoint.com/discuss/t/workflow-identity-search-loop-through-and-send-email/148424/5 "2025-08-25T13:03:27Z")

</div>

Closed on August 25, 2025, 1:03pm UTC

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