<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question How to find orphan records for the email logs in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/how-to-find-orphan-records-for-the-email-logs/m-p/3586702#M7689</link>
    <description>&lt;P&gt;We have deleted 5 lack email log records from the instance. Now we need to determine if there are any orphan attachments related to those deleted email logs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do we have any approach ?&lt;/P&gt;</description>
    <pubDate>Thu, 13 Aug 2026 08:47:23 GMT</pubDate>
    <dc:creator>nagarjunadI</dc:creator>
    <dc:date>2026-08-13T08:47:23Z</dc:date>
    <item>
      <title>How to find orphan records for the email logs</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-find-orphan-records-for-the-email-logs/m-p/3586702#M7689</link>
      <description>&lt;P&gt;We have deleted 5 lack email log records from the instance. Now we need to determine if there are any orphan attachments related to those deleted email logs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do we have any approach ?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2026 08:47:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-find-orphan-records-for-the-email-logs/m-p/3586702#M7689</guid>
      <dc:creator>nagarjunadI</dc:creator>
      <dc:date>2026-08-13T08:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to find orphan records for the email logs</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-find-orphan-records-for-the-email-logs/m-p/3586704#M7690</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;ahoy&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/1168398"&gt;@nagarjunadI&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;if it was by mistake, you can try to restore it from &lt;STRONG&gt;Deleted records&lt;/STRONG&gt; module:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="glideFather_0-1786610926743.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/526299i2F321F7D85A735E8/image-size/medium?v=v2&amp;amp;px=400" alt="glideFather_0-1786610926743.png" title="glideFather_0-1786610926743.png" /&gt;&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2026 08:49:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-find-orphan-records-for-the-email-logs/m-p/3586704#M7690</guid>
      <dc:creator>glideFather</dc:creator>
      <dc:date>2026-08-13T08:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to find orphan records for the email logs</title>
      <link>https://www.servicenow.com/community/community-central-forum/how-to-find-orphan-records-for-the-email-logs/m-p/3586708#M7691</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/1168398"&gt;@nagarjunadI&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you can run the background script and find out&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function() {
    var batchSize = 5000; // Limits processing chunk size to avoid memory overloads
    var totalOrphans = 0;
    var orphanIDs = [];

    var attachmentGR = new GlideRecord('sys_attachment');
    attachmentGR.addQuery('table_name', 'sys_email');
    attachmentGR.chooseWindow(0, batchSize); 
    attachmentGR.query();

    while (attachmentGR.next()) {
        var parentEmailID = attachmentGR.getValue('table_sys_id');
        
        // Check if the parent sys_email record still exists
        var emailGR = new GlideRecord('sys_email');
        if (!emailGR.get(parentEmailID)) {
            totalOrphans++;
            orphanIDs.push(attachmentGR.getUniqueValue());
            
            // Optional: Print details to logs for verification
            gs.info("Orphan Found: Attachment ID " + attachmentGR.getUniqueValue() + " for deleted Email ID: " + parentEmailID);
        }
    }

    gs.info("Execution complete. Total orphaned email attachments found in this batch: " + totalOrphans);
    // To delete them, you can loop through orphanIDs and run attachmentGR.deleteRecord()
})();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Chaitanya&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2026 08:57:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/how-to-find-orphan-records-for-the-email-logs/m-p/3586708#M7691</guid>
      <dc:creator>Chaitanya ILCR</dc:creator>
      <dc:date>2026-08-13T08:57:18Z</dc:date>
    </item>
  </channel>
</rss>

