<?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 Duplicate request creating with same Number in Virtual Agent forum</title>
    <link>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219692#M16263</link>
    <description>&lt;LI-CODE lang="markup"&gt;(function executeRule(current, previous /*null when async*/) {
    var cardOrderSysId = '000e49541b0e0d10683742e7bd4bcbed';

    if (current.cat_item.toString() !== cardOrderSysId) {
        return;
    }

    var tinNumber = current.variables.u_tin;
    var memberNumber = current.variables.u_member_number;

    if (!tinNumber &amp;amp;&amp;amp; !memberNumber) {
        return;
    }

    var existingReqItem = new GlideRecord('sc_req_item');
    existingReqItem.addQuery('cat_item', cardOrderSysId);
    existingReqItem.addQuery('sys_id', '!=', current.sys_id);
    if (tinNumber) {
        existingReqItem.addQuery('u_tin', tinNumber);
    }
    if (memberNumber) {
        existingReqItem.addQuery('u_member_number', memberNumber);
    }
    existingReqItem.query();

    if (existingReqItem.next()) {
        var req = current.request.getRefRecord();
            req.u_isduplicate = true;
            req.u_reference_ticket_number = existingReqItem.number;

            req.update();
        
    }
})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The above is my Business Rule, which runs after insert. The correct RITM is being updated, but I’m facing an issue. When I submit the card with an existing TIN or Member Number, two requests are being created with the same request number—one contains the requested item, while the other does not.&lt;/P&gt;&lt;P&gt;Why is this happening? Why is a duplicate request being created with the same number? How can I prevent this? This issue only occurs when a duplicate TIN or Member Number is found; other cases work fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VijayKumar4_0-1743069893748.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/430294i5E051016AFE0D566/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VijayKumar4_0-1743069893748.png" alt="VijayKumar4_0-1743069893748.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Please note that, I have created a workfow to assign some default values when this request submitted.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Mar 2025 10:05:05 GMT</pubDate>
    <dc:creator>Vijay Kumar4</dc:creator>
    <dc:date>2025-03-27T10:05:05Z</dc:date>
    <item>
      <title>Duplicate request creating with same Number</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219692#M16263</link>
      <description>&lt;LI-CODE lang="markup"&gt;(function executeRule(current, previous /*null when async*/) {
    var cardOrderSysId = '000e49541b0e0d10683742e7bd4bcbed';

    if (current.cat_item.toString() !== cardOrderSysId) {
        return;
    }

    var tinNumber = current.variables.u_tin;
    var memberNumber = current.variables.u_member_number;

    if (!tinNumber &amp;amp;&amp;amp; !memberNumber) {
        return;
    }

    var existingReqItem = new GlideRecord('sc_req_item');
    existingReqItem.addQuery('cat_item', cardOrderSysId);
    existingReqItem.addQuery('sys_id', '!=', current.sys_id);
    if (tinNumber) {
        existingReqItem.addQuery('u_tin', tinNumber);
    }
    if (memberNumber) {
        existingReqItem.addQuery('u_member_number', memberNumber);
    }
    existingReqItem.query();

    if (existingReqItem.next()) {
        var req = current.request.getRefRecord();
            req.u_isduplicate = true;
            req.u_reference_ticket_number = existingReqItem.number;

            req.update();
        
    }
})(current, previous);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;The above is my Business Rule, which runs after insert. The correct RITM is being updated, but I’m facing an issue. When I submit the card with an existing TIN or Member Number, two requests are being created with the same request number—one contains the requested item, while the other does not.&lt;/P&gt;&lt;P&gt;Why is this happening? Why is a duplicate request being created with the same number? How can I prevent this? This issue only occurs when a duplicate TIN or Member Number is found; other cases work fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VijayKumar4_0-1743069893748.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/430294i5E051016AFE0D566/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VijayKumar4_0-1743069893748.png" alt="VijayKumar4_0-1743069893748.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Please note that, I have created a workfow to assign some default values when this request submitted.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 10:05:05 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219692#M16263</guid>
      <dc:creator>Vijay Kumar4</dc:creator>
      <dc:date>2025-03-27T10:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate request creating with same Number</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219723#M16266</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/99675"&gt;@Vijay Kumar4&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you check if the variables&amp;nbsp;u_member_number and u_tin if empty/null? Please do gs.info to log the values of those variables and share the results if they are empty?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;gs.info(current.variables.u_tin);
gs.info(current.variables.u_member_number);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 10:20:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219723#M16266</guid>
      <dc:creator>Medi C</dc:creator>
      <dc:date>2025-03-27T10:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate request creating with same Number</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219732#M16267</link>
      <description>&lt;P&gt;Hello &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/99675"&gt;@Vijay Kumar4&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remove req.update()&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Shivalika&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My LinkedIn - &lt;A href="https://www.linkedin.com/in/shivalika-gupta-540346194" target="_blank"&gt;https://www.linkedin.com/in/shivalika-gupta-540346194&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My youtube - &lt;A href="https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY" target="_blank"&gt;https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&amp;amp;si=0WynLcOwNeEISQCY&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 10:24:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219732#M16267</guid>
      <dc:creator>Shivalika</dc:creator>
      <dc:date>2025-03-27T10:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate request creating with same Number</title>
      <link>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219791#M16269</link>
      <description>&lt;P&gt;As far as I remember the RITM is inserted into the DB _before_ the REQ.&lt;BR /&gt;When you then update the (at this point - non existant) request then the req.update() inserts an empty request record.&lt;BR /&gt;Try changing the Business rule to run async to give SN a chance to create the Req before you update it.&lt;BR /&gt;Also include some validation&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    if (existingReqItem.next()) {
		var req = new GlideRecord('sc_request');

        if(req.get(current.getValue('request') &amp;amp;&amp;amp; req.isValidRecord())){
            req.u_isduplicate = true;
            req.u_reference_ticket_number = existingReqItem.number;

            req.update();
		}
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also try changing the execution order to 1.000.000 on the BR as it wait a bit longer (after BR) before it runs&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 10:56:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/virtual-agent-forum/duplicate-request-creating-with-same-number/m-p/3219791#M16269</guid>
      <dc:creator>Simon Christens</dc:creator>
      <dc:date>2025-03-27T10:56:30Z</dc:date>
    </item>
  </channel>
</rss>

