Call javascript webscript from contoller

1. Create file at location - /source/web/components/documentlibrary/any-action.js
var nodeRef = record.node.linkedNode.nodeRef.replace(":/", "");
var me = this;
Alfresco.util.Ajax.request(
{
url: Alfresco.constants.PROXY_URI + "api/extensions/getPath/" + nodeRef,
method: Alfresco.util.Ajax.GET,
requestContentType: Alfresco.util.Ajax.JSON,
successCallback:{
fn: function changePath(response)
            {
if (response.json !== undefined)
{
var json = response.json;
var displayPath = json.displayPath;
var nodeRef = record.node.linkedNode.nodeRef;
var name = record.node.linkedNode.properties["cm:name"];
var pathInfo = displayPath.match("\/Sites\/([^\/]*)\/");                 
}
},
scope: me
            }
 });

2. Create file at location:
/config/alfresco/extension/templates/webscripts/com/test/util/displayPath/displayPath.get.desc.xml
<webscript>
   <shortname>Get Display Path</shortname>
   <description>Get the display path for a node</description>
   <url>/api/extensions/getPath/{item_store_type}/{item_store_id}/{item_id}</url>
   <format default="json"/>
   <authentication>user</authentication>
</webscript>

3. Create file at location:
/config/alfresco/extension/templates/webscripts/com/test/util/displayPath/displayPath.get.js
model.nodeRef = url.templateArgs.item_store_type;
model.nodeRef = model.nodeRef + "://" + url.templateArgs.item_store_id;
model.nodeRef = model.nodeRef + "/" + url.templateArgs.item_id;
var node = search.findNode(model.nodeRef);
if(node!=null) model.displayPath = node.displayPath;
else model.displayPath = null;

4. Create file at location:
/config/alfresco/extension/templates/webscripts/com/test/util/displayPath/displayPath.get.json.ftl
{
      "displayPath": "${displayPath}"
}

Comments

Popular posts from this blog

Install Alfresco Content Service 6.0 on ubuntu 16 using distribution zip

Alfresco basic authentication