0

I'm trying to make a webscript on Alfresco Share (and potentially a dashlet) that uses/calls a webscript on the Repository tier. I know I need a description XML file, a javascript and a result page being HTML or JSON. My question is what should be in those files?

This what I have compiled from various sources in the interwebs ;)

Desc:

<webscript>
   <shortname>Some name</shortname>
   <description>Some description</description>
   <family>dashlet</family>
   <url>/components/dashlets/upload/fileupload</url>
</webscript>

Javascript:

var connector = remote.connect("alfresco");
var data = connector.get("/upload/fileupload");//URL of Repository webscript     

// create json object from data
var result = eval('(' + data + ')');//This will parse json data
model.resultaat = result["resultaat"];//For adding data to model.

HTML.ftl result:

<#if resultaat??>
    ${resultaat}
<#else>
    Oh no, the folder name is empty!
</#if>

What I'm actually trying to do is call a Repo webscript that generates and put a report in the Repository. This works (see How to add a document to the Alfresco Repository with Java code?), but I want to call this from Share. So any suggestions?

EDIT: Updated the files.

Community
  • 1
  • 1
Teysz
  • 741
  • 9
  • 33

1 Answers1

1

Below is the code which you need to put in Share JS controller(webscript.get.js) for connecting to Repository webscript.

var connector = remote.connect("alfresco");
var data = connector.get("/sample/docprop.json");//URL of Repository webscript     

// create json object from data
var result = eval('(' + data + ')');//This will parse json data
model.docprop = result["docprop"];//For adding data to model.
Krutik Jayswal
  • 3,165
  • 1
  • 15
  • 38
  • I get the following error: Cannot parse XML: Scanner State 24 not Recognized. It says it fails on line 5 of this example: customfileupload.get.js#5(eval)#1 Btw the data from my repo webscript is JSON, so I don't know why it's asking about XML. – Teysz Jul 03 '15 at 12:43
  • If you see my comment , 3rd line is added for parsing json document and not xml. – Krutik Jayswal Jul 03 '15 at 12:46
  • It is JSON, I don't know why it says XML. – Teysz Jul 03 '15 at 12:47
  • give me all files you can use pastebin – Krutik Jayswal Jul 03 '15 at 12:47
  • For the repo webscript files see the accepted answer of this Q: http://stackoverflow.com/questions/30304918/how-to-add-a-document-to-the-alfresco-repository-with-java-code – Teysz Jul 03 '15 at 12:55
  • Response of http://stackoverflow.com/questions/30304918/how-to-add-a-document-to-the-alfresco-repository-with-java-code webscript should be in proper json format.You can check json in jsonlint.com website. – Krutik Jayswal Jul 03 '15 at 19:21
  • jsonlint.com only says: Expecting '{', '[' on line 1 when I use the URL in it. – Teysz Jul 06 '15 at 08:10
  • thats what , i was saying ,your json format is incorrect.Read more about what is json/ – Krutik Jayswal Jul 06 '15 at 08:37
  • I added <#escape x as jsonUtils.encodeJSONString(x)> { “resultaat”: "{$resultaat}" } #escape> to my repo JSON.ftl and guess what it gives a JSON response, but your answer still doesn't work... – Teysz Jul 06 '15 at 14:42
  • As i said ,read about json, ftl and webscript.You are not conceptually clear. – Krutik Jayswal Jul 06 '15 at 19:54
  • If only there was a site where I could ask questions... Oh wait. P.S. It IS a JSON response... What if the answer could be changed to XML instead? It seems it really wants XML. – Teysz Jul 07 '15 at 07:26
  • did you get this line var result = eval('(' + data + ')');//This will parse json data......Please dont responde if you are not getting – Krutik Jayswal Jul 07 '15 at 07:32
  • That is the line of doom where it all goes wrong. I am using that line, that IS the reason it is NOT working... – Teysz Jul 07 '15 at 07:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/82566/discussion-between-krutik-jayswal-and-teysz). – Krutik Jayswal Jul 07 '15 at 07:50
  • I've tried multiple times, changed files at both sides, and your answer still does not work. Could be because I'm trying to get a Repo web script that's using the Post method with the connector.get of your answer? – Teysz Jul 23 '15 at 10:00