<?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 Create Scripted REST API in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/create-scripted-rest-api/m-p/3559997#M1257974</link>
    <description>&lt;P&gt;HI All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a requirement to create a Scripted REST api to generate a JSON response from ServiceNow by combining cmdb_ci_service_auto and service_offering and business application table and I need to pick 3-4 fields from each table and send through JSON response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AM new to this completely. How to achieve this.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jun 2026 14:18:16 GMT</pubDate>
    <dc:creator>Aswin Chandras1</dc:creator>
    <dc:date>2026-06-16T14:18:16Z</dc:date>
    <item>
      <title>Create Scripted REST API</title>
      <link>https://www.servicenow.com/community/developer-forum/create-scripted-rest-api/m-p/3559997#M1257974</link>
      <description>&lt;P&gt;HI All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a requirement to create a Scripted REST api to generate a JSON response from ServiceNow by combining cmdb_ci_service_auto and service_offering and business application table and I need to pick 3-4 fields from each table and send through JSON response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AM new to this completely. How to achieve this.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2026 14:18:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/create-scripted-rest-api/m-p/3559997#M1257974</guid>
      <dc:creator>Aswin Chandras1</dc:creator>
      <dc:date>2026-06-16T14:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create Scripted REST API</title>
      <link>https://www.servicenow.com/community/developer-forum/create-scripted-rest-api/m-p/3560070#M1257992</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/291899"&gt;@Aswin Chandras1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this navigate to &lt;STRONG&gt;S&lt;/STRONG&gt;&lt;STRONG&gt;cripted rest services &amp;gt; Scripted REST APIs&amp;nbsp;&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; Create a new one - define &amp;lt;&lt;STRONG&gt;name&lt;/STRONG&gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;gt; In resources create a record with GET method&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use this script as per your requirement :&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var result = [];

    var grServiceAuto = new GlideRecord('cmdb_ci_service_auto');
    grServiceAuto.query();
    while (grServiceAuto.next()) {
        var serviceObj = {
            service_name: grServiceAuto.getValue('name'),
            service_id: grServiceAuto.getUniqueValue(),
            status: grServiceAuto.getValue('status'),
            owner: grServiceAuto.getDisplayValue('owned_by')
        };

        var grOffering = new GlideRecord('service_offering');
        grOffering.addQuery('service', grServiceAuto.sys_id);
        grOffering.query();
        if (grOffering.next()) {
            serviceObj.offering_name = grOffering.getValue('name');
            serviceObj.offering_id = grOffering.getUniqueValue();
            serviceObj.offering_status = grOffering.getValue('status');
        }

        var grApp = new GlideRecord('cmdb_ci_business_app');
        grApp.addQuery('used_for', grServiceAuto.sys_id);
        grApp.query();
        if (grApp.next()) {
            serviceObj.app_name = grApp.getValue('name');
            serviceObj.app_id = grApp.getUniqueValue();
            serviceObj.app_owner = grApp.getDisplayValue('owned_by');
        }

        result.push(serviceObj);
    }

    // Write JSON response
    response.setBody(result);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After configuring all you will get an endpoint like this known as resource path -&lt;/P&gt;&lt;P&gt;which you can test to get an output.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-06-16 215526.png" style="width: 597px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/520040i45D789E68049B16D/image-dimensions/597x68?v=v2" width="597" height="68" role="button" title="Screenshot 2026-06-16 215526.png" alt="Screenshot 2026-06-16 215526.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if my response helped mark as helpful and accept the solution.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jun 2026 16:29:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/create-scripted-rest-api/m-p/3560070#M1257992</guid>
      <dc:creator>yashkamde</dc:creator>
      <dc:date>2026-06-16T16:29:35Z</dc:date>
    </item>
  </channel>
</rss>

