AnsweredAssumed Answered

How to call the external web service in alfresco community 5.2

Question asked by anandhan on Sep 27, 2017
Latest reply on Nov 27, 2017 by krutik.jayswal

Hi,

 

I am trying to connect the external web service from my alfresco site to fetch the data and update that data in the ftl file. While connecting the external web service I am getting error like "Communication Failed". Please check the below code, If I made any mistake in this.

 

Steps followed:

 

Step 1: create the site-profile.get.html.ftl in below path "alfresco-home\tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\dashlets".  In this file I have referred the js file "site-profile.js"

 

<@script type="text/javascript" src="${url.context}/res/components/dashlets/site-profile.js" group="dashlets"/>

 

Step 2 : created the site-profile.js in below path "alfresco-home\tomcat\webapps\share\components\dashlets"

 

$(document).ready(function(){
   $(".viewMoreBtn").on('click',function(){
           updateList();
           $("#viewMoreSiteProfile").modal("show");
   });
});

function updateList(){
   Alfresco.util.Ajax.request({
   url: "http://services.groupkt.com/state/get/IND/UP",
   method: Alfresco.util.Ajax.GET,
   headers: ('Access-Control-Allow-Origin: *'),
   headers: ('Access-Control-Request-Headers: *'),
   headers: ('Access-Control-Allow-Methods: *'),
   requestContentType: Alfresco.util.Ajax.JSON,
      successCallback:{
         fn: function(res){
            appendOptiOnvalues(res)
         },
      },
      failureCallback:{
            fn: function(res){
                  alert("Error");
            },
         }
   });
}

 

function appendOptiOnvalues(result)
{
      $(".projectDescription").text(result.json.description);
      $(".projectName").text(result.json.title);
      $(".projectId").text(result.json.shortName);
}

Outcomes