<?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 Email script for populating Opened by value in notification in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372552#M4502</link>
    <description>&lt;P&gt;Hello Team&lt;BR /&gt;&lt;BR /&gt;I have a requirement in my current project where I need to send an email notification after approvals rejected so that I have created one email notification the approval table. In the notification body, I want to display the name of the person who rejected the HR case (i.e., the "Opened By" name), along with the HR case number.&lt;BR /&gt;However, I'm unable to find the fields for "Opened By", "HR Case No", and the name of the person who rejected the approval. Does anyone know how to write email script?&lt;/P&gt;</description>
    <pubDate>Sun, 07 Sep 2025 16:39:14 GMT</pubDate>
    <dc:creator>may13</dc:creator>
    <dc:date>2025-09-07T16:39:14Z</dc:date>
    <item>
      <title>Email script for populating Opened by value in notification</title>
      <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372552#M4502</link>
      <description>&lt;P&gt;Hello Team&lt;BR /&gt;&lt;BR /&gt;I have a requirement in my current project where I need to send an email notification after approvals rejected so that I have created one email notification the approval table. In the notification body, I want to display the name of the person who rejected the HR case (i.e., the "Opened By" name), along with the HR case number.&lt;BR /&gt;However, I'm unable to find the fields for "Opened By", "HR Case No", and the name of the person who rejected the approval. Does anyone know how to write email script?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Sep 2025 16:39:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372552#M4502</guid>
      <dc:creator>may13</dc:creator>
      <dc:date>2025-09-07T16:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Email script for populating Opened by value in notification</title>
      <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372555#M4503</link>
      <description>&lt;P&gt;For the above requirement, the email script won't be required. You can achieve the same thing by dot walk "&lt;/P&gt;&lt;P&gt;Approval for Number: ${sysapproval.number}&lt;/P&gt;&lt;P&gt;Approval for Opened by: ${sysapproval.opened_by} "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached the notification XML for your reference.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Sep 2025 16:59:42 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372555#M4503</guid>
      <dc:creator>Pankaj31</dc:creator>
      <dc:date>2025-09-07T16:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Email script for populating Opened by value in notification</title>
      <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372565#M4504</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/69239"&gt;@may13&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please use the below email script..&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function runMailScript(current, template, email, email_action, event) {
  
    var hrCaseGR = new GlideRecord('sn_hr_core_case'); // Replace with your HR case table name
    hrCaseGR.get(current.hr_case); // 'current' is the approval record
    // Print HR Case Number
    template.print('&amp;lt;strong&amp;gt;HR Case Number:&amp;lt;/strong&amp;gt; ' + hrCaseGR.getDisplayValue('number') + '&amp;lt;br/&amp;gt;');
    // Print Opened By
    template.print('&amp;lt;strong&amp;gt;Opened By:&amp;lt;/strong&amp;gt; ' + hrCaseGR.opened_by.getDisplayValue() + '&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;');

    // Find approver who rejected
    var appr = new GlideRecord('sysapproval_approver');
    appr.addQuery('sysapproval', current.sysapproval);
    appr.addQuery('state', 'rejected'); // state that indicates rejection
    appr.query();
    if (appr.next()) {
        template.print('&amp;lt;strong&amp;gt;Rejected By:&amp;lt;/strong&amp;gt; ' + appr.approver.getDisplayValue() + '&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;');
    }

    template.print('Your HR case approval was **rejected**. Please review and take necessary actions.');
})(current, template, email, email_action, event);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Sep 2025 18:06:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372565#M4504</guid>
      <dc:creator>kaushal_snow</dc:creator>
      <dc:date>2025-09-07T18:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Email script for populating Opened by value in notification</title>
      <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372660#M4505</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/69239"&gt;@may13&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use below mail script and use this in email notification&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Applies when used from a notification on sysapproval_approver
(function runMailScript(current, template, email, email_action, event) {
  try {
    // current is a sysapproval_approver record
    // Resolve the HR case from Approving/document_id
    var hr = current.sysapproval ? current.sysapproval.getRefRecord() : (current.document_id ? current.document_id.getRefRecord() : null);

    // HR case number and opened by
    var caseNumber = hr ? hr.getDisplayValue('number') : '';
    var openedBy = hr ? hr.getDisplayValue('opened_by') : '';

    // Rejecting approver and comments from the approval record that is rejected
    var rejectedBy = current.getDisplayValue('approver');
    var rejectionState = current.getValue('approval') || current.getValue('state'); // state/approval varies by instance
    var rejectionComment = '';

    // Safely pull the last journal entry if available
    try {
      if (current.comments) {
        // getJournalEntry(1) returns most recent entry
        rejectionComment = current.comments.getJournalEntry(1) || '';
      }
    } catch (e) {
      // ignore if no journal
    }

    // Print a compact block that the notification body can insert
    template.print('HR Case: ' + (caseNumber || '(none)') + '\n');
    template.print('Opened by: ' + (openedBy || '(none)') + '\n');
    template.print('Rejected by: ' + (rejectedBy || '(unknown)') + '\n');
    template.print('Approval state: ' + (rejectionState || '(unknown)') + '\n');
    if (rejectionComment)
      template.print('Rejection comments:\n' + rejectionComment + '\n');
  } catch (err) {
    template.print('HR Case: (error)\n');
  }
})(current, template, email, email_action, event);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will have the rejection comment as well in email notificaton.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;&lt;STRONG&gt;Bhimashankar H&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;-------------------------------------------------------------------------------------------------&lt;BR /&gt;If my response points you in the right directions, please consider marking it as 'Helpful' &amp;amp; 'Correct'. Thanks!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 02:57:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372660#M4505</guid>
      <dc:creator>Bhimashankar H</dc:creator>
      <dc:date>2025-09-08T02:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Email script for populating Opened by value in notification</title>
      <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372688#M4506</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/69239"&gt;@may13&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you cannot pick HR Case -&amp;gt; Opened By directly as notification is on sysapproval_approver table.&lt;/P&gt;
&lt;P&gt;You will have to use business rule on sysapproval_approver table, query HR Case and get Opened By and then include in recipient list&lt;/P&gt;
&lt;P&gt;where did you start with and where are you stuck?&lt;/P&gt;
&lt;P&gt;If my response helped please mark it correct and close the thread so that it benefits future readers.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 04:09:56 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372688#M4506</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2025-09-08T04:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Email script for populating Opened by value in notification</title>
      <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372785#M4515</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/69239"&gt;@may13&lt;/a&gt;&amp;nbsp; - i just tested below script it should work for you as well-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function runMailScript(current, template, email, email_action, event) {
    try {
        // Get the HR case record from the approval record
        var hrCase = current.sysapproval ? current.sysapproval.getRefRecord() : 
                     current.document_id ? current.document_id.getRefRecord() : null;
        
        if (hrCase &amp;amp;&amp;amp; hrCase.isValidRecord()) {
            // HR Case details
            template.print('HR Case Number: ' + hrCase.getDisplayValue('number') + '\n');
            template.print('Opened By: ' + hrCase.getDisplayValue('opened_by') + '\n');
        } else {
            template.print('HR Case Number: Not available\n');
            template.print('Opened By: Not available\n');
        }
        
        // Rejection details
        template.print('Rejected By: ' + current.getDisplayValue('approver') + '\n');
        template.print('Rejection Date: ' + current.getDisplayValue('sys_updated_on') + '\n');
        
        // Include rejection comments if available
        if (current.comments) {
            var latestComment = current.comments.getJournalEntry(1);
            if (latestComment) {
                template.print('Rejection Comments: ' + latestComment + '\n');
            }
        }
        
    } catch (e) {
        template.print('Error retrieving case details: ' + e.message);
    }
})(current, template, email, email_action, event);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;next step is to create notification on approval table, and also make sure to add filter condition where approving record -&amp;gt; task type&amp;nbsp; has to be hr case&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 06:11:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3372785#M4515</guid>
      <dc:creator>Ajay_Chavan</dc:creator>
      <dc:date>2025-09-08T06:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Email script for populating Opened by value in notification</title>
      <link>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3375416#M4556</link>
      <description>&lt;P&gt;hey&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/69239"&gt;@may13&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you get a chance to go through my previous reply.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If my response points you in the right directions, please consider marking it as 'Helpful' &amp;amp; 'Correct'. It will help future readers as well having similar kind of questions and close the thread.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;STRONG&gt;Bhimashankar H&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2025 05:30:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/email-script-for-populating-opened-by-value-in-notification/m-p/3375416#M4556</guid>
      <dc:creator>Bhimashankar H</dc:creator>
      <dc:date>2025-09-10T05:30:59Z</dc:date>
    </item>
  </channel>
</rss>

