cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker error in share webscript

vince20151
Champ in-the-making
Champ in-the-making
I have a very simple JS webscript on the Alfresco side (mytest.get.js)

function main() {
  model.someDesc= "Some description text");
}
main();


I can use this on an Alfresco webscript freemarker template and it works fine on the Alfresco side. Example

<div class="dashlet">
  <div class="title">Return Info WebScript</div>
  <div class="body">
    <br>Value is ${someDesc}</br>
  </div>
</div>


Now I want to access this data from the Share side in a webscript .Example sharetest.get.js
function main() {
  var data;
  var connector = remote.connect("alfresco");
  var result = connector.call("/mytest");

  if (result.status == status.STATUS_OK)
  {
    data = eval('(' + result + ')');
  }
  model.desc1= data.someDesc;
}
main();


And use desc1 in a freemarker template on the Share side

<div class="dashlet">
  <div class="title">Test getting value from Alfresco side</div>
  <div class="body">
    <br>Description is ${desc1}
  </div>
</div>


I keep getting error : Error on line 4, column 26 in sharetest.get.html.ftl Expecting a string, date or number here, Expression desc1 is instead a freemarker.template.SimpleHash

What did I do wrong and how to correct it.
Thanks a bunch!



4 REPLIES 4

parzgnat
Star Contributor
Star Contributor
ViNg,

Your Alfresco webscript FTL should be formatting the response as a JSON object, not as HTML.  When you call the Alfresco webscript from sharetest.get.js, you're running eval() on the result, and this method expects JSON.  Your FTL for your Alfresco webscript could look something like this:

<#escape x as jsonUtils.encodeJSONString(x)>
{
    "description" : "${someDesc}"
}
</#escape>


I hope this helps.

vince20151
Champ in-the-making
Champ in-the-making
Sorry I am a little new to FTL. Where do I put this code and what file?
Thanks a bunch!

mytest.get.json.ftl

vince20151
Champ in-the-making
Champ in-the-making
Thank you  much Parzgnat. It wworks well. Didn't know the view also plays important part. Thought only the controller is used for data. That was a great help!