<?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: Get auto number for record just inserted with GlideRecord in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683555#M340481</link>
    <description>&lt;P&gt;In some UI Actions that create records on another table, they declare a variable when the current record is inserted. This will capture the inserted record as an object that you can use in other parts of the script.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;I am guessing that the edata_table is a reference field. If that is the case, then you can leverage the sys_id of the record that was inserted. Here is your example changed to leverage this:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14585759960339703 jive_text_macro" data-renderedposition="155_8_1192_400" jivemacro_uid="_14585759960339703"&gt;&lt;P&gt;//set email parts to variables &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var body = email.body_text; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var emSubject = email.subject; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var sender = gs.getUser(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//var ed = current.number //Commented out since we do not want to caputre this yet.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//identify specific REGEX &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var PT = body.match(/PT\d{8}/); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//create PT record &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var gr = new GlideRecord('x_tekm_edata_pt_list'); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gr.pt = PT.toString(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gr.insert(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//place text in fields, and create new eData record &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.ptcmid = PT.toString(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.original_email = "Subject: " + emSubject + "\nBody: " + body; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.requestor = sender.getDisplayName(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var edID = current.insert(); &amp;nbsp; //Changed to use edID to capture the current inserted object&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//create relationship record &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var rel = new GlideRecord('x_tekm_edata_m2m_pt_lists_edata_tables'); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.pt_list = PT.toString(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.edata_table = edID.sys_id; &amp;nbsp; //Guessing this is a reference field and thus needs the unique identifier defined.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.insert(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Let me know if you are more successful.&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 21 Mar 2016 16:00:16 GMT</pubDate>
    <dc:creator>ccajohnson</dc:creator>
    <dc:date>2016-03-21T16:00:16Z</dc:date>
    <item>
      <title>Get auto number for record just inserted with GlideRecord</title>
      <link>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683554#M340480</link>
      <description>&lt;P&gt;I am just wondering if there is a quick and easy command to use to get the 'number' field of a record just created from a glide insert.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created a custom application involving a many to many relation ship table. From an inbound action I create a record in a table that has auto numbering turned on (call it "ED123") . That same inbound action also pulls data from the email to identify and create a separate record on a separate table (call it "PT456"). I want to them take those two records, and create a record on the m2m relationship table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The part of this that I am having trouble with is that the auto assigned "ED" number isn't generated until after the insert() command. Is there a way to still query it a 'current' after insert? or do I just have to build a query to identify the most recently created?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my Inbound Action:&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14585727041426424" data-renderedposition="218_8_1192_400" jivemacro_uid="_14585727041426424" modifiedtitle="true"&gt;&lt;P&gt;//set email parts to variables&lt;/P&gt;&lt;P&gt;var body = email.body_text;&lt;/P&gt;&lt;P&gt;var emSubject = email.subject;&lt;/P&gt;&lt;P&gt;var sender = gs.getUser();&lt;/P&gt;&lt;P&gt;var ed = current.number //This is the part that doesn't work for me, because the record's 'number' hasn't been generated yet&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//identify specific REGEX&lt;/P&gt;&lt;P&gt;var PT = body.match(/PT\d{8}/);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//create PT record&lt;/P&gt;&lt;P&gt;var gr = new GlideRecord('x_tekm_edata_pt_list');&lt;/P&gt;&lt;P&gt;gr.pt = PT.toString();&lt;/P&gt;&lt;P&gt;gr.insert();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//place text in fields, and create new eData record&lt;/P&gt;&lt;P&gt;current.ptcmid = PT.toString();&lt;/P&gt;&lt;P&gt;current.original_email = "Subject: " + emSubject + "\nBody: " + body;&lt;/P&gt;&lt;P&gt;current.requestor = sender.getDisplayName();&lt;/P&gt;&lt;P&gt;current.insert();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//create relationship record&lt;/P&gt;&lt;P&gt;var rel = new GlideRecord('x_tekm_edata_m2m_pt_lists_edata_tables');&lt;/P&gt;&lt;P&gt;rel.pt_list = PT.toString();&lt;/P&gt;&lt;P&gt;rel.edata_table = ed; &amp;nbsp; //This is where it would put the ED number, but when the variable was declared, the number didn't exist yet.&lt;/P&gt;&lt;P&gt;rel.insert();&lt;/P&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2016 15:10:38 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683554#M340480</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2016-03-21T15:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Get auto number for record just inserted with GlideRecord</title>
      <link>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683555#M340481</link>
      <description>&lt;P&gt;In some UI Actions that create records on another table, they declare a variable when the current record is inserted. This will capture the inserted record as an object that you can use in other parts of the script.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;I am guessing that the edata_table is a reference field. If that is the case, then you can leverage the sys_id of the record that was inserted. Here is your example changed to leverage this:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14585759960339703 jive_text_macro" data-renderedposition="155_8_1192_400" jivemacro_uid="_14585759960339703"&gt;&lt;P&gt;//set email parts to variables &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var body = email.body_text; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var emSubject = email.subject; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var sender = gs.getUser(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//var ed = current.number //Commented out since we do not want to caputre this yet.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//identify specific REGEX &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var PT = body.match(/PT\d{8}/); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//create PT record &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var gr = new GlideRecord('x_tekm_edata_pt_list'); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gr.pt = PT.toString(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gr.insert(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//place text in fields, and create new eData record &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.ptcmid = PT.toString(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.original_email = "Subject: " + emSubject + "\nBody: " + body; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;current.requestor = sender.getDisplayName(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var edID = current.insert(); &amp;nbsp; //Changed to use edID to capture the current inserted object&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//create relationship record &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var rel = new GlideRecord('x_tekm_edata_m2m_pt_lists_edata_tables'); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.pt_list = PT.toString(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.edata_table = edID.sys_id; &amp;nbsp; //Guessing this is a reference field and thus needs the unique identifier defined.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.insert(); &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Let me know if you are more successful.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:00:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683555#M340481</guid>
      <dc:creator>ccajohnson</dc:creator>
      <dc:date>2016-03-21T16:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get auto number for record just inserted with GlideRecord</title>
      <link>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683556#M340482</link>
      <description>&lt;P&gt;Not sure whether it will work or not but have you tried using function :- "getNextObjNumberPadded()" &lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:14:48 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683556#M340482</guid>
      <dc:creator>SME</dc:creator>
      <dc:date>2016-03-21T16:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Get auto number for record just inserted with GlideRecord</title>
      <link>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683557#M340483</link>
      <description>&lt;P&gt;Thanks for the input Christopher! I was able to get it to work with your suggestion, with just a minor tweak; adding the 'sys_id' onto the variable wasn't necessary. I also had to change my declaration of the PT field on the relationship table. So it ended up as:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14585769773192915" data-renderedposition="71_8_1192_208" jivemacro_uid="_14585769773192915" modifiedtitle="true"&gt;&lt;P&gt;//create PT record&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var gr = new GlideRecord('x_tekm_edata_pt_list');&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gr.pt = PT.toString();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var ptID = gr.insert();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//get current&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var edID = current.insert();&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;//create relationship record&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var rel = new GlideRecord('x_tekm_edata_m2m_pt_lists_edata_tables');&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.pt_list = ptID;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.edata_table = edID;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;rel.insert();&lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:18:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/get-auto-number-for-record-just-inserted-with-gliderecord/m-p/1683557#M340483</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2016-03-21T16:18:10Z</dc:date>
    </item>
  </channel>
</rss>

