<?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 Re: Dynamically retrieving the approver user in ATF and impersonating them in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396082#M1231402</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/448076"&gt;@aruncr0122&lt;/a&gt;.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I really appreciate your effort in helping me.&lt;BR /&gt;&lt;BR /&gt;Every time I run the test, the sys_id is different. I can’t set the sys_id manually, you know?&lt;BR /&gt;&lt;BR /&gt;That’s why I need a way to retrieve the sys_id dynamically from the step 36.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Oct 2025 12:58:26 GMT</pubDate>
    <dc:creator>rafaelmach7x</dc:creator>
    <dc:date>2025-10-02T12:58:26Z</dc:date>
    <item>
      <title>Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3386118#M1229286</link>
      <description>&lt;P&gt;Hello community — I'm facing an issue with ATF impersonation and hope someone can point out what I might be missing.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Environment &amp;amp; context&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;I have an ATF test where:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Step 36&lt;/STRONG&gt; is a Record Query that successfully returns a sysapproval_approver record (I can see the approval record sys_id in Step 36 output).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Step 37&lt;/STRONG&gt; is a &lt;EM&gt;Run Server-side Script&lt;/EM&gt; that should read the Step 36 output, query sysapproval_approver, extract the approver (a reference to sys_user), and return a record output in the format the Impersonate step expects:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;outputs.record = &lt;SPAN class=""&gt;{&lt;/SPAN&gt; document_id&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;"&amp;lt;sys_user_sys_id&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; table&lt;SPAN class=""&gt;:&lt;/SPAN&gt; &lt;SPAN class=""&gt;"sys_user"&lt;/SPAN&gt; &lt;SPAN class=""&gt;}&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;What I expect to happen&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Step 37 prepares outputs.record with the approver sys_user id.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Step 38 (Impersonate)&lt;/STRONG&gt; is configured to use {{Step 37: Run Server Side Script.Record}} (dot-walk → Step 37 → Record → document_id) and should impersonate that user so the remaining ATF steps run in that user's context.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;What actually happens&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Step 37 executes successfully (no script error).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;However, &lt;STRONG&gt;Step 38 fails&lt;/STRONG&gt; with:&lt;BR /&gt;User to impersonate not specified&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;In Step 38 I selected the user via the dot-walk UI (Step 37 → Record → document_id). The Impersonate field shows that reference, but the step fails at runtime.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;What I tried already&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;I made the Step 37 script robust so it detects either steps[36].first_record.document_id or steps[36].record_id (I log both).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;I tried returning outputs.record as shown above.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;I also tried returning an alternative name (outputs.user) and other shapes, but Impersonate only accepts a dot-walkable Record → document_id.&lt;BR /&gt;&lt;BR /&gt;Here´s the code -&amp;nbsp;Step 37 script (full) that I used&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="markup"&gt;(function(outputs, steps, stepResult) {
    try {
        gs.info("ATF Step 37: starting - reading Step 36 outputs...");

        var approvalRecordSysId = null;
        if (steps[36] &amp;amp;&amp;amp; steps[36].first_record &amp;amp;&amp;amp; steps[36].first_record.document_id) {
            approvalRecordSysId = steps[36].first_record.document_id;
            gs.info("ATF Step 37 debug: found steps[36].first_record.document_id = " + approvalRecordSysId);
        } else if (steps[36] &amp;amp;&amp;amp; steps[36].record_id) {
            approvalRecordSysId = steps[36].record_id;
            gs.info("ATF Step 37 debug: found steps[36].record_id = " + approvalRecordSysId);
        } else if (steps[36] &amp;amp;&amp;amp; steps[36].first_record) {
            approvalRecordSysId = steps[36].first_record;
            gs.info("ATF Step 37 debug: found steps[36].first_record (fallback) = " + approvalRecordSysId);
        }

        if (!approvalRecordSysId) {
            stepResult.setFailed("Step 37 failed: could not read approval record id from Step 36. Inspect Step 36 outputs.");
            return;
        }

        var grApproval = new GlideRecord("sysapproval_approver");
        if (!grApproval.get(approvalRecordSysId)) {
            stepResult.setFailed("Step 37 failed: sysapproval_approver record not found for id: " + approvalRecordSysId);
            return;
        }

        var approverSysId = grApproval.getValue("approver");
        if (!approverSysId) {
            stepResult.setFailed("Step 37 failed: 'approver' field is empty on sysapproval_approver record: " + approvalRecordSysId);
            return;
        }

        gs.info("ATF Step 37 debug: approver sys_id = " + approverSysId);

        outputs.record = {
            document_id: approverSysId,
            table: "sys_user"
        };

        outputs.record_id = approverSysId;
        outputs.record_table = "sys_user";

        stepResult.setOutputMessage("Step 37 succeeded: prepared outputs.record for sys_user " + approverSysId);
    } catch (ex) {
        stepResult.setFailed("Step 37 exception: " + ex.message);
    }
})(outputs, steps, stepResult);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Important:&amp;nbsp;If I manually enter the approver’s username in the Impersonate step, the test runs successfully until the end. This confirms that Step 36 is correct and is returning the sys_id of the approval record.&lt;BR /&gt;&lt;BR /&gt;Here´s some prints that might me usefull.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rafaelmach7x_0-1758296930140.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/471346iA79D3334C8B8B12D/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="rafaelmach7x_0-1758296930140.png" alt="rafaelmach7x_0-1758296930140.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rafaelmach7x_1-1758297058581.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/471347i4B62A8208C4205C5/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="rafaelmach7x_1-1758297058581.png" alt="rafaelmach7x_1-1758297058581.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rafaelmach7x_2-1758297296143.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/471348i8EF33DF72F6331D0/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="rafaelmach7x_2-1758297296143.png" alt="rafaelmach7x_2-1758297296143.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 38 failed: User to impersonate not specified&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Is the outputs.record = { document_id: "&amp;lt;sys_id&amp;gt;", table: "sys_user" } shape definitely the correct format for the ATF Impersonate step to consume?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Could there be a timing/serialization issue where the Impersonate step evaluates the dot-walk reference before the Run Script outputs are fully available? If so, any workaround?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Has anyone seen the Impersonate step return “User to impersonate not specified” even though the preceding Run Script produced outputs.record? If so, what fixed it?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance for any help or pointers. Any sample working snippet or a note about version-specific behavior would be very appreciated.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;BR /&gt;Rafael&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 19 Sep 2025 15:57:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3386118#M1229286</guid>
      <dc:creator>rafaelmach7x</dc:creator>
      <dc:date>2025-09-19T15:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3392173#M1230480</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570780"&gt;@rafaelmach7x&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You can use the below simple script to do the same action.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;function&lt;/SPAN&gt;&lt;SPAN&gt;(outputs, steps, stepResult) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; prevStep = &lt;/SPAN&gt;&lt;SPAN&gt;"XXXXXXXXX"&lt;/SPAN&gt;&lt;SPAN&gt;; &lt;/SPAN&gt;&lt;SPAN&gt;//Sys Id of Step 36&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; approval = &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;GlideRecord&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"sysapproval_approver"&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; approval.&lt;/SPAN&gt;&lt;SPAN&gt;get&lt;/SPAN&gt;&lt;SPAN&gt;(steps(prevStep).first_record);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; approverSysId = approval.getValue(&lt;/SPAN&gt;&lt;SPAN&gt;"approver"&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; approver = &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt; &lt;SPAN&gt;GlideRecord&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'sys_user'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; approver.&lt;/SPAN&gt;&lt;SPAN&gt;get&lt;/SPAN&gt;&lt;SPAN&gt;(approverSysId);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (!approver.getUniqueValue()) {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stepResult.setOutputMessage(&lt;/SPAN&gt;&lt;SPAN&gt;"Unable to find the User to Impersonate"&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stepResult.setFailed();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;false&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; } &lt;/SPAN&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stepResult.setOutputMessage(&lt;/SPAN&gt;&lt;SPAN&gt;"User found for Impersonation is - "&lt;/SPAN&gt;&lt;SPAN&gt; + approver.getDisplayValue(&lt;/SPAN&gt;&lt;SPAN&gt;"name"&lt;/SPAN&gt;&lt;SPAN&gt;));&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stepResult.setSuccess();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; outputs.record_id = approverSysId;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;true&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;})(outputs, steps, stepResult);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my answer helped, please mark it as helpful or accept as the solution.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Chidanand&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Sep 2025 20:30:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3392173#M1230480</guid>
      <dc:creator>Chidanand_VK</dc:creator>
      <dc:date>2025-09-27T20:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3393503#M1230799</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Chidanand_VK!&lt;BR /&gt;&lt;BR /&gt;Thanks for your help!&lt;BR /&gt;&lt;BR /&gt;I don’t want to manually enter the sys_id, because that’s not sustainable in tests that may change.&lt;BR /&gt;&lt;BR /&gt;Ideally, the script or ATF itself should be able to dynamically determine the sys_id of step 36, or the step should be configured to pass this information through an output.&lt;BR /&gt;&lt;BR /&gt;In this line of code, I understood that you want me to manually enter the sys_id of step 36.&lt;BR /&gt;&amp;nbsp;var&amp;nbsp;prevStep =&amp;nbsp;"XXXXXXXXX";&amp;nbsp;//Sys Id of Step 36&lt;BR /&gt;&lt;BR /&gt;That’s why I tried this approach below in my script, but it didn’t work...&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;steps[36] &amp;amp;&amp;amp; steps[36].first_record &amp;amp;&amp;amp; steps[36].first_record.document_id&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Is there a way to dynamically determine the sys_id of step 36?&lt;BR /&gt;&lt;BR /&gt;Kind regards!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2025 18:26:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3393503#M1230799</guid>
      <dc:creator>rafaelmach7x</dc:creator>
      <dc:date>2025-09-29T18:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3393522#M1230802</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570780"&gt;@rafaelmach7x&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Step 37, you’re outputting:&lt;/P&gt;&lt;P&gt;outputs.record = { document_id: approverSysId, table: "sys_user" };&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In Step 38 (Impersonate), you’re dot-walking to Record → document_id.&lt;/P&gt;&lt;P&gt;But ATF’s Impersonate step doesn’t understand document_id — it expects a sys_id in the record object. That’s why you’re seeing “Usuário para representação não especificado” (User to impersonate not specified).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; Fix: update Step 37 to return sys_id instead:&lt;/P&gt;&lt;P&gt;outputs.record = {&lt;BR /&gt;sys_id: approverSysId,&lt;BR /&gt;table: "sys_user"&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Alternatively, you can set:&lt;/P&gt;&lt;P&gt;outputs.record_id = approverSysId;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;and then in the Impersonate step, select Record → sys_id (not document_id).&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2025 18:56:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3393522#M1230802</guid>
      <dc:creator>aruncr0122</dc:creator>
      <dc:date>2025-09-29T18:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3394517#M1231061</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/448076"&gt;@aruncr0122&lt;/a&gt;.&lt;BR /&gt;&lt;BR /&gt;Thanks for your answer.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Unfortunately, in Step 38 – Impersonate – ATF only allows me to select Record → document_id.&lt;BR /&gt;&lt;BR /&gt;See the image below ...&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rafaelmach7x_0-1759238806598.png" style="width: 999px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/473588iB72A39E2CED8C303/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="rafaelmach7x_0-1759238806598.png" alt="rafaelmach7x_0-1759238806598.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the last test log&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rafaelmach7x_1-1759241902501.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/473611iB1D893A4D2C0C064/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="rafaelmach7x_1-1759241902501.png" alt="rafaelmach7x_1-1759241902501.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The most recent version of the script with your suggested adjustments ...&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function(outputs, steps, stepResult) {
    // --- Try to resolve the sys_id from Step 36 in multiple ways ---
    var prevStep = steps['36'];
    var prevStepSysId = null;

    if (!prevStep) {
        stepResult.setOutputMessage("Step 36 outputs not found.");
        stepResult.setFailed();
        return false;
    }

    // Try the most common patterns
    if (prevStep.record_id) {
        prevStepSysId = prevStep.record_id;
    } else if (prevStep.sys_id) {
        prevStepSysId = prevStep.sys_id;
    } else if (prevStep.record &amp;amp;&amp;amp; prevStep.record.sys_id) {
        prevStepSysId = prevStep.record.sys_id;
    } else if (prevStep.record &amp;amp;&amp;amp; prevStep.record.document_id) {
        prevStepSysId = prevStep.record.document_id;
    }

    // If still not found, fail gracefully
    if (!prevStepSysId) {
        stepResult.setOutputMessage("Unable to determine sys_id from Step 36 outputs.");
        stepResult.setFailed();
        return false;
    }

    // --- Now query the approval record from sysapproval_approver ---
    var approval = new GlideRecord("sysapproval_approver");
    if (!approval.get(prevStepSysId)) {
        stepResult.setOutputMessage("Approval record not found using sys_id from Step 36.");
        stepResult.setFailed();
        return false;
    }

    // Get the approver sys_id
    var approverSysId = approval.getValue("approver");

    // Lookup the approver in sys_user
    var approver = new GlideRecord("sys_user");
    if (!approver.get(approverSysId)) {
        stepResult.setOutputMessage("User not found for impersonation.");
        stepResult.setFailed();
        return false;
    }

    // Success case
    stepResult.setOutputMessage("User found for impersonation: " + approver.getDisplayValue("name"));
    stepResult.setSuccess();

    // Output for next step (Impersonate)
    outputs.record = {
        sys_id: approverSysId,
        table: "sys_user"
    };

    // Alternative output (in case Impersonate step expects record_id)
    outputs.record_id = approverSysId;

    return true;
})(outputs, steps, stepResult);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Is there a way to make it work?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2025 14:22:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3394517#M1231061</guid>
      <dc:creator>rafaelmach7x</dc:creator>
      <dc:date>2025-09-30T14:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3394675#M1231102</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/448076"&gt;@aruncr0122&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/291610"&gt;@Chidanand_VK&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I also tried this script but it didn't work.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(function(outputs, steps, stepResult) {
    // Try to retrieve Step 36 in multiple ways
    var prevStep = steps['36'] || steps['Step 36'] || steps['step36'] || steps['step_36'];

    if (!prevStep) {
        stepResult.setOutputMessage("❌ Could not find Step 36 in steps object.");
        stepResult.setFailed();
        return false;
    }

    // Try to extract the sys_id from Step 36 outputs
    var prevStepSysId = prevStep.record_id 
        || prevStep.sys_id 
        || (prevStep.record &amp;amp;&amp;amp; prevStep.record.sys_id) 
        || (prevStep.record &amp;amp;&amp;amp; prevStep.record.document_id);

    if (!prevStepSysId) {
        stepResult.setOutputMessage("❌ Could not retrieve sys_id from Step 36 outputs.");
        stepResult.setFailed();
        return false;
    }

    // Query the sysapproval_approver record using the sys_id
    var approval = new GlideRecord("sysapproval_approver");
    if (!approval.get(prevStepSysId)) {
        stepResult.setOutputMessage("❌ Could not find approval record from Step 36 sys_id.");
        stepResult.setFailed();
        return false;
    }

    // Get the approver sys_id
    var approverSysId = approval.getValue("approver");

    // Look up the sys_user record
    var approver = new GlideRecord("sys_user");
    if (!approver.get(approverSysId)) {
        stepResult.setOutputMessage("❌ Unable to find the User to impersonate.");
        stepResult.setFailed();
        return false;
    }

    // Success
    stepResult.setOutputMessage("✅ User found for impersonation: " + approver.getDisplayValue("name"));
    stepResult.setSuccess();

    // Return the sys_id in a way ATF can use
    outputs.record = {
        sys_id: approverSysId,
        table: "sys_user"
    };

    // Also provide as record_id for flexibility
    outputs.record_id = approverSysId;

    return true;

})(outputs, steps, stepResult);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;And after testing with ATF ... I'm getting this error message from the test log ...&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":cross_mark:"&gt;❌&lt;/span&gt; Could not find Step 36 in steps object.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2025 17:20:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3394675#M1231102</guid>
      <dc:creator>rafaelmach7x</dc:creator>
      <dc:date>2025-09-30T17:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3395597#M1231327</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570780"&gt;@rafaelmach7x&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you try to use previous step sys_id to get submitted record sys_id by following way.&lt;/P&gt;&lt;P&gt;var STEP_SYS_ID = 'previous step sys_id'; // Your Submit form test step sys_id&lt;/P&gt;&lt;P&gt;var record_sys_id = steps(STEP_SYS_ID).record_id); // get submitted form record sys_id.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2025 15:48:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3395597#M1231327</guid>
      <dc:creator>aruncr0122</dc:creator>
      <dc:date>2025-10-01T15:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3395972#M1231384</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570780"&gt;@rafaelmach7x&lt;/a&gt;&amp;nbsp;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"I don’t want to manually enter the sys_id, because that’s not sustainable in tests that may change."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When you mention NOT sustainable, What that mean? any below statement or anything else?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-&amp;gt;If you copy the Test and run that New Test, it will not work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;-&amp;gt;The execution will NOT successfully works every time?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 08:51:07 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3395972#M1231384</guid>
      <dc:creator>Chidanand_VK</dc:creator>
      <dc:date>2025-10-02T08:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396082#M1231402</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/448076"&gt;@aruncr0122&lt;/a&gt;.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I really appreciate your effort in helping me.&lt;BR /&gt;&lt;BR /&gt;Every time I run the test, the sys_id is different. I can’t set the sys_id manually, you know?&lt;BR /&gt;&lt;BR /&gt;That’s why I need a way to retrieve the sys_id dynamically from the step 36.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 12:58:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396082#M1231402</guid>
      <dc:creator>rafaelmach7x</dc:creator>
      <dc:date>2025-10-02T12:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396083#M1231403</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/291610"&gt;@Chidanand_VK&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I really appreciate your effort in helping me.&lt;BR /&gt;&lt;BR /&gt;Every time I run the test, the sys_id is different. I can’t set the sys_id manually, you know?&lt;BR /&gt;&lt;BR /&gt;That’s why I need a way to retrieve the sys_id dynamically from the step 36.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 12:56:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396083#M1231403</guid>
      <dc:creator>rafaelmach7x</dc:creator>
      <dc:date>2025-10-02T12:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396644#M1231506</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570780"&gt;@rafaelmach7x&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Ok...so you are talking about the 'sys_id' of the record of the Record query (in your case Approval), right?&lt;/P&gt;&lt;P&gt;If Yes, then you are wrong. You don't need to set the sys_id every time when you run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI: If you set the Sys Id of the Test step manually in the script (which I showed), then it works all the time. Unless you delete the Test step and Create a new one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just give it a try by setting the Sys Id of the Test step 36 in the script manually and try to run multiple times.&lt;/P&gt;&lt;P&gt;I am sure it works as I was doing the same in my case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my answer helped, please mark it as helpful or accept as the solution.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Chidanand&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 08:51:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396644#M1231506</guid>
      <dc:creator>Chidanand_VK</dc:creator>
      <dc:date>2025-10-03T08:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically retrieving the approver user in ATF and impersonating them</title>
      <link>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396712#M1231519</link>
      <description>&lt;P&gt;Hi &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/570780"&gt;@rafaelmach7x&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;What I meant by “previous step sys_id” is the ATF step sys_id of Step 36, which will always remain the same. The returned output (record sys_id) might change every time, but the step sys_id itself is fixed.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;// Step 36 sys_id (this never changes for that test step)&lt;BR /&gt;var STEP_SYS_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';&lt;/P&gt;&lt;P&gt;// Retrieve the submitted record sys_id dynamically&lt;BR /&gt;var record_sys_id = steps(STEP_SYS_ID).record_id;&lt;/P&gt;&lt;P&gt;gs.info("Submitted record sys_id: " + record_sys_id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This way, you don’t have to hardcode the record sys_id — it will always be fetched dynamically from Step 36’s output.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Oct 2025 07:34:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/dynamically-retrieving-the-approver-user-in-atf-and/m-p/3396712#M1231519</guid>
      <dc:creator>aruncr0122</dc:creator>
      <dc:date>2025-10-03T07:34:32Z</dc:date>
    </item>
  </channel>
</rss>

