<?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: how to create nested json dynamically and have to use REST message  in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708433#M365359</link>
    <description>&lt;P&gt;If you are working with a GlideList field, the following is an example that may help you&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var obj = {
	requestor: current.getDisplayValue('caller_id'),
	email: current.caller_id.email.toString(),
	Details: []
};

var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', 'IN', current.getValue('watch_list'));
userGR.query();

while(userGR.next()) {
	obj.Details.push({
		name: userGR.getValue('user_name')
	});
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which would generate a JSON that looks like&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;{
    "requestor": "Abel Tuter",
    "email": "abel.tuter@example.com",
    "Details": [
        {
            "name": "adela.cervantsz"
        },
        {
            "name": "aileen.mottern"
        },
        {
            "name": "abraham.lincoln"
        }
    ]
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 15 Feb 2021 18:45:52 GMT</pubDate>
    <dc:creator>Callum Ridley1</dc:creator>
    <dc:date>2021-02-15T18:45:52Z</dc:date>
    <item>
      <title>how to create nested json dynamically and have to use REST message</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708427#M365353</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;
&lt;P&gt;we are using BR to fetching the incident record values, but unable &amp;nbsp;to create a nested JSON pattern as below&lt;/P&gt;
&lt;P&gt;{&lt;BR /&gt; "requestor": "test",&lt;BR /&gt; "email": "abc@xyz.com",&lt;/P&gt;
&lt;P&gt;"&lt;STRONG&gt;Details&lt;/STRONG&gt;": [{&lt;BR /&gt; "name": "test",&lt;BR /&gt; "age": "New",&lt;BR /&gt; "place": "",&lt;BR /&gt; "action": "Add",&lt;BR /&gt; "&lt;STRONG&gt;city&lt;/STRONG&gt;": ["ABC", "XYZ"]},&lt;BR /&gt; {"name": "yes",&lt;BR /&gt; "age": "New",&lt;BR /&gt; "place": "hello",&lt;BR /&gt; "action": "Add",&lt;BR /&gt; "city": ["ABC", "XYZ"]}&lt;BR /&gt; ]}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Where Details will dynamically add, depends on users info and city attribute is an array and how the REST message should set to the above JSON&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions, please&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 17:34:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708427#M365353</guid>
      <dc:creator>String</dc:creator>
      <dc:date>2021-02-15T17:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to create nested json dynamically and have to use REST message</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708428#M365354</link>
      <description>&lt;P&gt;Please could you show what you have tried so far? I don't see why there would be an issue generating the JSON you have shown an example of.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 17:43:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708428#M365354</guid>
      <dc:creator>Callum Ridley1</dc:creator>
      <dc:date>2021-02-15T17:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to create nested json dynamically and have to use REST message</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708429#M365355</link>
      <description>&lt;P&gt;Hi Callum,&lt;/P&gt;
&lt;P&gt;Thanks for your quick reply ,Please check the below script&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var requestJSON = {&lt;BR /&gt; "requestor": "" + current.req,&lt;BR /&gt; "email": "" + current.user_mail,&lt;BR /&gt; "name": "" + current.user_name,&lt;BR /&gt; "age": "" +current.user_age,&lt;BR /&gt; "place": "" +current.user_place,&lt;BR /&gt; "action": "" +current.place,&lt;BR /&gt; "city": "" +current.city&lt;BR /&gt; };&lt;BR /&gt; var r = new sn_ws.RESTMessageV2('outbound', 'INC');&lt;BR /&gt; r.setRequestHeader("Accept", "application/json");&lt;BR /&gt; r.setRequestBody(JSON.stringify(requestJSON));&lt;/P&gt;
&lt;P&gt;var response = r.execute();&lt;/P&gt;
&lt;P&gt;Iam using the above script to create the json ,but iam getting normal json&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how to&amp;nbsp;create&amp;nbsp; the above json where Details attribute&amp;nbsp; will add dynamically expand&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 17:53:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708429#M365355</guid>
      <dc:creator>String</dc:creator>
      <dc:date>2021-02-15T17:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to create nested json dynamically and have to use REST message</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708430#M365356</link>
      <description>&lt;P&gt;What are you expecting the fill the&amp;nbsp;&lt;STRONG&gt;Details&lt;/STRONG&gt; array with? Your business rule is only looking at one record (the current record), but it looks like you want to include data from multiple records?&lt;/P&gt;
&lt;P&gt;What are the trigger conditions for your business rule?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 18:16:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708430#M365356</guid>
      <dc:creator>Callum Ridley1</dc:creator>
      <dc:date>2021-02-15T18:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to create nested json dynamically and have to use REST message</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708431#M365357</link>
      <description>&lt;P&gt;Multiple&amp;nbsp;user info&amp;nbsp;will insert into incident form, So&amp;nbsp; need to fetch user info and add to JSON in details attributes dynamically and the city is multiple places, So&amp;nbsp;have to&amp;nbsp; array&amp;nbsp;&lt;/P&gt;
&lt;P&gt;trigger conditions for your business rule: when a new record inserted&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 18:28:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708431#M365357</guid>
      <dc:creator>String</dc:creator>
      <dc:date>2021-02-15T18:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to create nested json dynamically and have to use REST message</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708432#M365358</link>
      <description>&lt;P&gt;Is the information on multiple users added to a List (GlideList) element?&lt;/P&gt;
&lt;P&gt;Maybe add a screenshot of the form you're trying to generate the data from and highlight&amp;nbsp;the field(s) you are trying to get the data from.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 18:31:41 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708432#M365358</guid>
      <dc:creator>Callum Ridley1</dc:creator>
      <dc:date>2021-02-15T18:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to create nested json dynamically and have to use REST message</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708433#M365359</link>
      <description>&lt;P&gt;If you are working with a GlideList field, the following is an example that may help you&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var obj = {
	requestor: current.getDisplayValue('caller_id'),
	email: current.caller_id.email.toString(),
	Details: []
};

var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', 'IN', current.getValue('watch_list'));
userGR.query();

while(userGR.next()) {
	obj.Details.push({
		name: userGR.getValue('user_name')
	});
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which would generate a JSON that looks like&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;{
    "requestor": "Abel Tuter",
    "email": "abel.tuter@example.com",
    "Details": [
        {
            "name": "adela.cervantsz"
        },
        {
            "name": "aileen.mottern"
        },
        {
            "name": "abraham.lincoln"
        }
    ]
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Feb 2021 18:45:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-create-nested-json-dynamically-and-have-to-use-rest/m-p/1708433#M365359</guid>
      <dc:creator>Callum Ridley1</dc:creator>
      <dc:date>2021-02-15T18:45:52Z</dc:date>
    </item>
  </channel>
</rss>

