<?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 Scripting to Map a Field in Transform Map in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2603032#M1012487</link>
    <description>&lt;P&gt;I have 2 fields on table build a transform map to load the data into table.&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="Vamsi43_0-1688310018939.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271037iC267B630061ECFD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Vamsi43_0-1688310018939.png" alt="Vamsi43_0-1688310018939.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to map the "Service" Field using script.&lt;BR /&gt;Can you please help me on this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If the Service is not empty, map each value of the Excel with the right Service to Target.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I wrote the below script which is not working&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;answer = (function transformEntry(source) {
    if (target.u_delivery_time.nil()) {
        target.u_delivery_time = source.u_delivery_time;
    }
})(source);&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Vamsi43_1-1688310393427.png" style="width: 778px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271038iD6073DA3F522BE21/image-dimensions/778x284?v=v2" width="778" height="284" role="button" title="Vamsi43_1-1688310393427.png" alt="Vamsi43_1-1688310393427.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 02 Jul 2023 15:07:03 GMT</pubDate>
    <dc:creator>Vamsi43</dc:creator>
    <dc:date>2023-07-02T15:07:03Z</dc:date>
    <item>
      <title>Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2603032#M1012487</link>
      <description>&lt;P&gt;I have 2 fields on table build a transform map to load the data into table.&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="Vamsi43_0-1688310018939.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271037iC267B630061ECFD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Vamsi43_0-1688310018939.png" alt="Vamsi43_0-1688310018939.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want to map the "Service" Field using script.&lt;BR /&gt;Can you please help me on this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If the Service is not empty, map each value of the Excel with the right Service to Target.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I wrote the below script which is not working&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;answer = (function transformEntry(source) {
    if (target.u_delivery_time.nil()) {
        target.u_delivery_time = source.u_delivery_time;
    }
})(source);&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Vamsi43_1-1688310393427.png" style="width: 778px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271038iD6073DA3F522BE21/image-dimensions/778x284?v=v2" width="778" height="284" role="button" title="Vamsi43_1-1688310393427.png" alt="Vamsi43_1-1688310393427.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jul 2023 15:07:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2603032#M1012487</guid>
      <dc:creator>Vamsi43</dc:creator>
      <dc:date>2023-07-02T15:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2603060#M1012500</link>
      <description>&lt;P&gt;Hello &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/351133"&gt;@Vamsi43&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;I think you need to return the value in you script, because you don't have access to the target object. Here what you script need to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;answer = (function transformEntry(source) {
    if (target.u_delivery_time.nil()) {
        return source.u_delivery_time;
    }
})(source);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;I&gt;&lt;SPAN&gt;If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.&lt;/SPAN&gt;&lt;/I&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;best regards&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jul 2023 17:07:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2603060#M1012500</guid>
      <dc:creator>MahaAgineo</dc:creator>
      <dc:date>2023-07-02T17:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2604828#M1013136</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/519212"&gt;@MahaAgineo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to check both the conditions on the script&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. If the Service is not empty, map each value of the Excel with the right Service&amp;nbsp; to Target.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2.&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;If Service&lt;/STRONG&gt;&lt;STRONG&gt;&amp;nbsp;is empty, then set the Delivery time with the value of the Catalog Item.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote the below script which is not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;answer = (function transformEntry(source) {
    if (target.u_delivery_time.nil()) {
        var delivery;
        var catalogItemGR = new GlidRecord("sc_cat_item");
        catalogItemGR.addNullQuery('delivery_time');
        catalogItemGR.query();
        while (catalogItemGR.next()) {
            delivery = source.delivery_time;
        }
        return delivery; // return the value to be put into the target field
    } else {
        return source.u_delivery_time;
    }
})(source);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jul 2023 16:47:46 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2604828#M1013136</guid>
      <dc:creator>Vamsi43</dc:creator>
      <dc:date>2023-07-04T16:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605221#M1013317</link>
      <description>&lt;P&gt;Hello &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/351133"&gt;@Vamsi43&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;You don't have access to the target object, so you need to use a transform map script (set run Script to true see Screenshot), and use this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;(function transformRow(source, target, map, log, isUpdate) {
if (target.u_delivery_time.nil()) {
        var delivery;
        var catalogItemGR = new GlidRecord("sc_cat_item");
        catalogItemGR.addNullQuery('delivery_time');
        catalogItemGR.query();
        while (catalogItemGR.next()) {
            delivery = source.delivery_time;
        }
        target.u_delivery_time = delivery; // return the value to be put into the target field
    } else {
       target.u_delivery_time  = source.u_delivery_time;
    }
})(source, target, map, log, action === "update");&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 class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MahaAgineo_0-1688543932761.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271516i7B0B3A48DBB24270/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MahaAgineo_0-1688543932761.png" alt="MahaAgineo_0-1688543932761.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And I don't think you need the else because the field will be by default mapped to the source, with the normal field field mapping (without script)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;I&gt;&lt;SPAN&gt;If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.&lt;/SPAN&gt;&lt;/I&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;best regards&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 08:02:45 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605221#M1013317</guid>
      <dc:creator>MahaAgineo</dc:creator>
      <dc:date>2023-07-05T08:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605346#M1013379</link>
      <description>&lt;P&gt;Then what about the Field Maps script i need erase it all and map direct like this?&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="Vamsi43_0-1688549146180.png" style="width: 560px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271537i359778FE80B7CC58/image-dimensions/560x119?v=v2" width="560" height="119" role="button" title="Vamsi43_0-1688549146180.png" alt="Vamsi43_0-1688549146180.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 09:26:03 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605346#M1013379</guid>
      <dc:creator>Vamsi43</dc:creator>
      <dc:date>2023-07-05T09:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605368#M1013385</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/351133"&gt;@Vamsi43&lt;/a&gt;&amp;nbsp;Yes I think so, try it and tell me, and sorry I saw a mistake in my script, it should look like this, whitout (&lt;/P&gt;&lt;PRE&gt;(function transformRow(source, target, map, log, isUpdate) {&lt;/PRE&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;you need to put only this:&lt;/P&gt;&lt;PRE&gt;if (target.u_delivery_time.nil()) {
        var delivery;
        var catalogItemGR = new GlidRecord("sc_cat_item");
        catalogItemGR.addNullQuery('delivery_time');
        catalogItemGR.query();
        while (catalogItemGR.next()) {
            delivery = source.delivery_time;
        }
        target.u_delivery_time = delivery; // return the value to be put into the target field
    } else {
       target.u_delivery_time  = source.u_delivery_time;
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;I&gt;&lt;SPAN&gt;If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.&lt;/SPAN&gt;&lt;/I&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;best regards&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 09:32:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605368#M1013385</guid>
      <dc:creator>MahaAgineo</dc:creator>
      <dc:date>2023-07-05T09:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605380#M1013390</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/519212"&gt;@MahaAgineo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like Below i defined the script and Map fields.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Vamsi43_1-1688550123756.png" style="width: 538px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271545i0FFA6604D429890F/image-dimensions/538x340?v=v2" width="538" height="340" role="button" title="Vamsi43_1-1688550123756.png" alt="Vamsi43_1-1688550123756.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I Loaded the below data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Vamsi43_0-1688550061931.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271544iA85BDCEB3633DC25/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Vamsi43_0-1688550061931.png" alt="Vamsi43_0-1688550061931.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It not written the Adobe Acrobat Pro catalog item "Delivery time = 2days ".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 09:45:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605380#M1013390</guid>
      <dc:creator>Vamsi43</dc:creator>
      <dc:date>2023-07-05T09:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605388#M1013393</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/351133"&gt;@Vamsi43&lt;/a&gt;&amp;nbsp;Upadate the script without first and last line&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 09:46:50 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605388#M1013393</guid>
      <dc:creator>MahaAgineo</dc:creator>
      <dc:date>2023-07-05T09:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605400#M1013399</link>
      <description>&lt;P&gt;But still not working&lt;/P&gt;&lt;P&gt;Delivery Time on Catalog item is "Duration" type but Variable on Table is "String" field. Do you think we suppose update the script ?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 09:55:55 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605400#M1013399</guid>
      <dc:creator>Vamsi43</dc:creator>
      <dc:date>2023-07-05T09:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605405#M1013401</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/351133"&gt;@Vamsi43&lt;/a&gt;&amp;nbsp;Yes you need to convert String to Duration field&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 10:02:02 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605405#M1013401</guid>
      <dc:creator>MahaAgineo</dc:creator>
      <dc:date>2023-07-05T10:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605411#M1013404</link>
      <description>&lt;P&gt;Ok: so in the field script use this (I assume you only have days):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var delivery_time = source.u_delivery_time ;//source.u_delivery_time
var day_split = delivery_time.split(' ');
var day = day_split[0];
var result= new GlideDuration(day  +' 00:00:00');
return result;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;and in the run script use this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (target.u_delivery_time.nil()) {
        var delivery;
        var catalogItemGR = new GlidRecord("sc_cat_item");
        catalogItemGR.addNullQuery('delivery_time');
        catalogItemGR.query();
        while (catalogItemGR.next()) {
            delivery = source.delivery_time;
        }
target.u_delivery_time = delivery;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 05 Jul 2023 10:12:33 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605411#M1013404</guid>
      <dc:creator>MahaAgineo</dc:creator>
      <dc:date>2023-07-05T10:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting to Map a Field in Transform Map</title>
      <link>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605528#M1013451</link>
      <description>&lt;P&gt;I got the values like this into the table.&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="Vamsi43_0-1688557338174.png" style="width: 548px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/271582i5A89C60A27A96F3E/image-dimensions/548x133?v=v2" width="548" height="133" role="button" title="Vamsi43_0-1688557338174.png" alt="Vamsi43_0-1688557338174.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 11:43:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/scripting-to-map-a-field-in-transform-map/m-p/2605528#M1013451</guid>
      <dc:creator>Vamsi43</dc:creator>
      <dc:date>2023-07-05T11:43:22Z</dc:date>
    </item>
  </channel>
</rss>

