<?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 Help with transform field map script in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290707#M1209166</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling with a field map script, and could use some guidance from the community.&lt;/P&gt;&lt;P&gt;Due to limitations, the source spreadsheet columns cannot be modified, so I need to handle everything via scripting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of the source fields, &lt;STRONG&gt;source.u_softwaretype&lt;/STRONG&gt;, contains values formatted like:&lt;BR /&gt;&lt;STRONG&gt;"GH001 - Software Not found"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;What I need to do is:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Extract just the code portion (&lt;STRONG&gt;"GH001"&lt;/STRONG&gt;) from the text.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Perform a lookup in the &lt;STRONG&gt;x_software_list_code_mapping&lt;/STRONG&gt; table where:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;supplier = 'WILLIAMS'&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;code = 'GH001'&lt;/STRONG&gt; (the extracted value)&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;From the matched record, retrieve the &lt;STRONG&gt;serial_number&lt;/STRONG&gt;&amp;nbsp;field value.&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Populate the target reference field with that&amp;nbsp;&lt;STRONG&gt;serial_number&lt;/STRONG&gt;&amp;nbsp;field value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the script I tried so far but is not working:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snowman15_0-1750098534478.jpeg" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/448981iBDC54A2925F333C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snowman15_0-1750098534478.jpeg" alt="Snowman15_0-1750098534478.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;(function transformEntry(source) {&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var match = source.u_softwaretype.match(/(GH\d{3})/); &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;if (!match) return "";&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;STRONG&gt;var extractedCode = match[1];&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var gr = new GlideRecord('x_software_list_code_mapping');&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.addQuery('supplier', 'WILLIAMS');&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.addQuery('code', extractedCode);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.setLimit(1);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.query();&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;STRONG&gt;if (gr.next()) {&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;return gr.serial_number; &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;STRONG&gt;return ""; &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;})(source);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 16 Jun 2025 19:00:01 GMT</pubDate>
    <dc:creator>Snowman15</dc:creator>
    <dc:date>2025-06-16T19:00:01Z</dc:date>
    <item>
      <title>Help with transform field map script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290707#M1209166</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling with a field map script, and could use some guidance from the community.&lt;/P&gt;&lt;P&gt;Due to limitations, the source spreadsheet columns cannot be modified, so I need to handle everything via scripting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of the source fields, &lt;STRONG&gt;source.u_softwaretype&lt;/STRONG&gt;, contains values formatted like:&lt;BR /&gt;&lt;STRONG&gt;"GH001 - Software Not found"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;What I need to do is:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Extract just the code portion (&lt;STRONG&gt;"GH001"&lt;/STRONG&gt;) from the text.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Perform a lookup in the &lt;STRONG&gt;x_software_list_code_mapping&lt;/STRONG&gt; table where:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;supplier = 'WILLIAMS'&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;code = 'GH001'&lt;/STRONG&gt; (the extracted value)&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;From the matched record, retrieve the &lt;STRONG&gt;serial_number&lt;/STRONG&gt;&amp;nbsp;field value.&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Populate the target reference field with that&amp;nbsp;&lt;STRONG&gt;serial_number&lt;/STRONG&gt;&amp;nbsp;field value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the script I tried so far but is not working:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snowman15_0-1750098534478.jpeg" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/448981iBDC54A2925F333C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snowman15_0-1750098534478.jpeg" alt="Snowman15_0-1750098534478.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;(function transformEntry(source) {&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var match = source.u_softwaretype.match(/(GH\d{3})/); &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;if (!match) return "";&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;STRONG&gt;var extractedCode = match[1];&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;var gr = new GlideRecord('x_software_list_code_mapping');&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.addQuery('supplier', 'WILLIAMS');&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.addQuery('code', extractedCode);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.setLimit(1);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;gr.query();&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;STRONG&gt;if (gr.next()) {&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;return gr.serial_number; &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;STRONG&gt;return ""; &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;})(source);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 16 Jun 2025 19:00:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290707#M1209166</guid>
      <dc:creator>Snowman15</dc:creator>
      <dc:date>2025-06-16T19:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with transform field map script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290753#M1209175</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/606366"&gt;@Snowman15&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try adding logs inside your script and where it breaks, if target is a reference field , try returning "&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;!--  ScriptorStartFragment  --&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;gr&lt;/SPAN&gt;&lt;SPAN&gt;.getUniqueValue&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt; &lt;SPAN&gt;// returns sys_id".&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Yaswanth&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;&lt;!--  ScriptorEndFragment  --&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jun 2025 19:45:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290753#M1209175</guid>
      <dc:creator>YaswanthKurre</dc:creator>
      <dc:date>2025-06-16T19:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with transform field map script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290759#M1209176</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Sometimes you need to convert a field name to string to make it work. Try the below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;STRONG&gt;(function transformEntry(source) {&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;var match = source.u_softwaretype.toString().match(/(GH\d{3})/);&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;if (!match) return "";&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;STRONG&gt;var extractedCode = match[1];&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;var gr = new GlideRecord('x_software_list_code_mapping');&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;gr.addQuery('supplier', 'WILLIAMS');&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;gr.addQuery('code', extractedCode);&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;gr.setLimit(1);&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;gr.query();&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;STRONG&gt;if (gr.next()) {&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;return gr.serial_number.toString();&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;STRONG&gt;return "";&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;})(source);&lt;/STRONG&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 16 Jun 2025 19:46:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290759#M1209176</guid>
      <dc:creator>palanikumar</dc:creator>
      <dc:date>2025-06-16T19:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with transform field map script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290774#M1209179</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/399739"&gt;@YaswanthKurre&lt;/a&gt;&amp;nbsp;thanks. Tried this but didn't work&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jun 2025 20:16:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290774#M1209179</guid>
      <dc:creator>Snowman15</dc:creator>
      <dc:date>2025-06-16T20:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Help with transform field map script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290775#M1209180</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/23358"&gt;@palanikumar&lt;/a&gt;&amp;nbsp;thank you, unfortunately this didn't work either.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Jun 2025 20:18:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3290775#M1209180</guid>
      <dc:creator>Snowman15</dc:creator>
      <dc:date>2025-06-16T20:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help with transform field map script</title>
      <link>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3291502#M1209377</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/606366"&gt;@Snowman15&lt;/a&gt;&amp;nbsp;, try this,&lt;BR /&gt;&lt;STRONG&gt;gr.addQuery('code', extractedCode.toString());&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jun 2025 12:45:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/help-with-transform-field-map-script/m-p/3291502#M1209377</guid>
      <dc:creator>Muhammad Salar</dc:creator>
      <dc:date>2025-06-17T12:45:49Z</dc:date>
    </item>
  </channel>
</rss>

