<?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>topic Re: Problem with json request in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104491#M29630</link>
    <description>&lt;P&gt;Unless you provide any details on your 500 error, little help can be provided.&lt;/P&gt;
&lt;P&gt;I am not sure what "your format" actually is - are you trying to generate some weird JSONP response content? The example with the "die" / "json_encode" functions really does not do anything to clear that up. Do you want to generate a response that would look similar to the result of these function calls? Then what actually does the "die" function generate? (I am not aware by what framework / language that function is provided and would not know what it does)&lt;/P&gt;</description>
    <pubDate>Sun, 27 Oct 2019 16:47:07 GMT</pubDate>
    <dc:creator>afaust</dc:creator>
    <dc:date>2019-10-27T16:47:07Z</dc:date>
    <item>
      <title>Problem with json request</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104488#M29627</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;I`m trying to make a webscript which will be able to:&lt;/P&gt;&lt;P&gt;1. receive json request;&lt;BR /&gt;2. get and transform argument from json request to java format;&lt;BR /&gt;3. find node in a specific folder using json argument as a search request;&lt;BR /&gt;4. get properties from found node;&lt;BR /&gt;5. transform found properties back to json string;&lt;BR /&gt;6. send answer in json;&lt;/P&gt;&lt;P&gt;Example of json request that I want to process&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$postData = array(
	'didNumber' =&amp;gt; '0443334000',
	'srcNumber' =&amp;gt; '0670219424',
	'companyID' =&amp;gt; '3041',
	'requestType' =&amp;gt; 'gettingCallSettings'
);&lt;/PRE&gt;&lt;P&gt;I`ve created next files after reading about json processing in Alfresco:&lt;/P&gt;&lt;P&gt;.get.desc.xml&lt;/P&gt;&lt;PRE&gt;&amp;lt;webscript&amp;gt;
  &amp;lt;shortname&amp;gt;negotiate&amp;lt;/shortname&amp;gt;
  &amp;lt;description&amp;gt;negotiate JSON&amp;lt;/description&amp;gt;
  &amp;lt;url&amp;gt;/negotiate&amp;lt;/url&amp;gt;
  &amp;lt;authentication&amp;gt;guest&amp;lt;/authentication&amp;gt;
  &amp;lt;negotiate accept="application/json"&amp;gt;json&amp;lt;/negotiate&amp;gt;
&amp;lt;/webscript&amp;gt;&lt;/PRE&gt;&lt;P&gt;.get.json.ftl&lt;/P&gt;&lt;PRE&gt;{"response": "myObjAsString"}&lt;/PRE&gt;&lt;P&gt;.get.js&lt;/P&gt;&lt;PRE&gt;    var tel = json.get("srcNumber");
	var node = search.luceneSearch("@cm\\:name:\"" + nodeName+ "\" AND PARENT:\"workspace://SpacesStore/61d28f13-24e0-434a-8b90-5ea54d2fafa2\"");
	var name = node.properties["zkz:Name"];                                                                                                                             
    var myObj = {'name':'name'};
    var myObjAsString = jsonUtils.toJSONString(myObj);
    model.myObjAsString = myObjAsString;&lt;/PRE&gt;&lt;P&gt;But every time I try to execute my srcipt I receive something like this:&lt;/P&gt;&lt;PRE&gt;{
    "status" : 
  {
    "code" : 500,
    "name" : "Internal Error",
    "description" : "An error inside the HTTP server which prevented it from fulfilling the request."
  },  
  
  "message" : "09220628 Cannot locate template processor for template org\/alfresco\/negotiate.get.json",  
  "exception" : "org.springframework.extensions.webscripts.WebScriptException - 09220628 Cannot locate template processor for template org\/alfresco\/negotiate.get.json",&lt;/PRE&gt;&lt;P&gt;or if I clean all data from&amp;nbsp;.get.js I receive text from .ftl file.&lt;/P&gt;&lt;P&gt;In the end I need to send back something like this:&lt;/P&gt;&lt;PRE&gt;die(json_encode(array(
	'customerData' =&amp;gt; array(
		'name' =&amp;gt; '1111111',
		'description' =&amp;gt; '11111111111',
	)
)));&lt;/PRE&gt;&lt;P&gt;Please, can someone help me with js file? Can it be on Java or it must be in Json format?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 16:38:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104488#M29627</guid>
      <dc:creator>h_john</dc:creator>
      <dc:date>2019-10-23T16:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with json request</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104489#M29628</link>
      <description>&lt;P&gt;jsonUtils.toJSONString should not be used - it does not fully support all native JS types - instead return the JS object as part of the model, and use FTL rendering to construct a proper JSON object structure.&lt;/P&gt;
&lt;P&gt;search.luceneSearch should not be used - Lucene is legacy, only supported for unit / integration tests, does not receive any performance improvements etc.&lt;/P&gt;
&lt;P&gt;You are missing a format element in the desc.xml to specify that the default response type should be JSON and thus the JSON FTL be used.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 20:25:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104489#M29628</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2019-10-23T20:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with json request</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104490#M29629</link>
      <description>&lt;P&gt;Thank you for you advice!&lt;/P&gt;&lt;P&gt;I made some changes using this tutorials&amp;nbsp;&lt;A href="https://docs.alfresco.com/5.2/references/dev-extension-points-webscripts.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.alfresco.com/5.2/references/dev-extension-points-webscripts.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It works but now I need to use another answer format and can't change *.ftl file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In tutorial it was:&lt;/P&gt;&lt;PRE&gt;&amp;lt;#assign datetimeformat="EEE, dd MMM yyyy HH:mm:ss zzz"&amp;gt;
{
    "acmeDocs" : [
        &amp;lt;#list acmeDocs as acmeDoc&amp;gt;
            {
                "name"          : "${acmeDoc.name}",
                "creator"       : "${acmeDoc.creator}",
                "createdDate"   : "${acmeDoc.createdDate?string(datetimeformat)}",
                "modifier"      : "${acmeDoc.modifier}",
                "modifiedDate"  : "${acmeDoc.modifiedDate?string(datetimeformat)}",
                "docId"         : "${acmeDoc.docId!"Unknown"}",
                "securityClass" : "${acmeDoc.securityClassification!"Unknown"}"
            }
            &amp;lt;#if acmeDoc_has_next&amp;gt;,&amp;lt;/#if&amp;gt;
        &amp;lt;/#list&amp;gt;
    ]
}&lt;/PRE&gt;&lt;P&gt;Ad it gives ne answer:&lt;/P&gt;&lt;PRE&gt;{
    "acmeDocs" : [
            {
                "name"          : "weqweqweqwrerwerwerweqwe",
                "creator"       : "i.gerts",
                "createdDate"   : "Sun, 27 Oct 2019 14:50:46 EET",
                "modifier"      : "i.gerts",
                "modifiedDate"  : "Sun, 27 Oct 2019 14:50:49 EET",
                "docId"         : "Unknown",
                "securityClass" : "Unknown"
            }
            
    ]
}&lt;/PRE&gt;&lt;P&gt;I tried to change it to my format:&lt;/P&gt;&lt;PRE&gt;die(json_encode(array(
	'customerData' =&amp;gt; array(
		'name' =&amp;gt; '${acmeDoc.name}',
		'description' =&amp;gt; '${acmeDoc.creator}',
	)
)));&lt;/PRE&gt;&lt;P&gt;But it gives me 500 error&lt;/P&gt;&lt;P&gt;what I need to change in FTL?&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2019 13:11:59 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104490#M29629</guid>
      <dc:creator>h_john</dc:creator>
      <dc:date>2019-10-27T13:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with json request</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104491#M29630</link>
      <description>&lt;P&gt;Unless you provide any details on your 500 error, little help can be provided.&lt;/P&gt;
&lt;P&gt;I am not sure what "your format" actually is - are you trying to generate some weird JSONP response content? The example with the "die" / "json_encode" functions really does not do anything to clear that up. Do you want to generate a response that would look similar to the result of these function calls? Then what actually does the "die" function generate? (I am not aware by what framework / language that function is provided and would not know what it does)&lt;/P&gt;</description>
      <pubDate>Sun, 27 Oct 2019 16:47:07 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104491#M29630</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2019-10-27T16:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with json request</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104492#M29631</link>
      <description>&lt;P&gt;Hi there. I have had the same issue. Thanks for the information&amp;nbsp;&lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://connect.hyland.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 12:38:06 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104492#M29631</guid>
      <dc:creator>stivemorgan567</dc:creator>
      <dc:date>2019-10-28T12:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with json request</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104493#M29632</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a little progress with it.&lt;/P&gt;&lt;P&gt;Now my files is:&lt;/P&gt;&lt;P&gt;acme-documents.get.desc.xml&lt;/P&gt;&lt;PRE&gt;&amp;lt;webscript&amp;gt;
    &amp;lt;shortname&amp;gt;Search ACME Documents&amp;lt;/shortname&amp;gt;
    &amp;lt;description&amp;gt;Returns metadata as JSON for all ACME documents in the repository that matches search keyword&amp;lt;/description&amp;gt;
    &amp;lt;url&amp;gt;/tutorial/acmedocs?q={keyword}&amp;lt;/url&amp;gt;
    &amp;lt;authentication&amp;gt;user&amp;lt;/authentication&amp;gt;
    &amp;lt;format default="json"&amp;gt;argument&amp;lt;/format&amp;gt;
    &amp;lt;family&amp;gt;Alfresco Tutorials&amp;lt;/family&amp;gt;
&amp;lt;/webscript&amp;gt;&lt;/PRE&gt;&lt;P&gt;acme-documents.get.js&lt;/P&gt;&lt;PRE&gt;function AcmeDocumentInfo(doc) {
    this.name = doc.properties["kezkz:Name"];
    this.linkToCrmUrl = doc.properties["kezkz:Email"];
    this.linkToCrmTitle = "Go to Alfresco";
    this.assignedToEmployeeNumber = doc.properties["kezkz:Napravl"];
}

function main() {
    var searchKeyword = json.get('srcNumber');
    if (searchKeyword == null || searchKeyword.length == 0) {
        searchKeyword = "";
    } 
var sort1 = 
{ 
  column: "@{http://www.alfresco.org/model/content/1.0}modified", 
  ascending: false 
}; 

var sort2 = 
{ 
  column: "@{http://www.alfresco.org/model/content/1.0}created", 
  ascending: false
}; 

var paging = 
{ 
  maxItems: 1, 
  skipCount: 0 
}; 



		var def =
  {
  query: "kezkz:Telefone:searchKeyword", 
  store: "workspace://SpacesStore", 
  language: "fts-alfresco", 
  sort: [sort1, sort2], 
  page: paging,
  };
  
      var acmeDocNodes = search.query(def);

    if (acmeDocNodes == null || acmeDocNodes.length == 0) {
        status.code = 404;
        status.message = searchKeyword;
        status.redirect = true;
    } else {
	        var acmeDocInfos = new Array();
        for (i = 0; i &amp;lt; acmeDocNodes.length; i++) {
            acmeDocInfos[i] = new AcmeDocumentInfo(acmeDocNodes[i]);
        }
        model.acmeDocs = acmeDocInfos;
        return model;
}
}

main();
                                                            &lt;/PRE&gt;&lt;P&gt;acme-documents.get.json.ftl&lt;/P&gt;&lt;PRE&gt;   { "customerData" : 
    &amp;lt;#list acmeDocs as acmeDoc&amp;gt;
            {
                "name"          : "${acmeDoc.name}",
                "linkToCrmUrl"          : "${acmeDoc.linkToCrmUrl}",
                "linkToCrmTitle"          : "Go to CRM",
                "assignedToEmployeeNumber"          : "${acmeDoc.assignedToEmployeeNumber}",
            }
        &amp;lt;/#list&amp;gt;
}&lt;/PRE&gt;&lt;P&gt;It works when I set manualy search query and I can find nodes in folder and receive answer, but I still can not get args from json request use them as a searchKeyword and put to a query string.&lt;/P&gt;&lt;P&gt;When I use&amp;nbsp; &amp;nbsp;json.get('srcNumber')&lt;/P&gt;&lt;P&gt;I receive an error "JSON is not defined"&lt;/P&gt;&lt;P&gt;And even if I try to set "searchKeyword" manualy I can not put this var to my search...&lt;/P&gt;&lt;P&gt;This part of my code:&amp;nbsp; query: "kezkz:Telefone:searchKeyword",&lt;/P&gt;&lt;P&gt;tries to find text "searchKeyword" but not the text I defined for "var&amp;nbsp;searchKeyword" earlier.&lt;/P&gt;&lt;P&gt;What I do wrong?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 22:47:32 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104493#M29632</guid>
      <dc:creator>h_john</dc:creator>
      <dc:date>2019-11-10T22:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with json request</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104494#M29633</link>
      <description>&lt;P&gt;&lt;SPAN&gt;srcNumber - is a argument name in my GET request, which I send to Alfresco.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In the end I need to:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1. Take Tel number from GET request&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Search datalist item by this tel number&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. Send back same data list item properties in a json format&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 22:53:02 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-with-json-request/m-p/104494#M29633</guid>
      <dc:creator>h_john</dc:creator>
      <dc:date>2019-11-10T22:53:02Z</dc:date>
    </item>
  </channel>
</rss>

