cancel
Showing results for 
Search instead for 
Did you mean: 

Document action in Share to call json webscript of Alfresco

agey
Champ in-the-making
Champ in-the-making
Hi all,

I have a webscript created in Alfresco to return json data about a document. Now I want to call this webscript from Share in a menu link of each document but I don't know how do it. I created a action in share-config-custom.xml:

<action id="sm.doclib.action.detail.sending.e-invoices"
   icon="detailed-view-on"
   type="pagelink"
   label="actions.document.detail.sending.e-invoice">
      <param name="page">/components/emfra/detailSendingeInvoice?nodeId={node.nodeRef}</param>
      <evaluator>evaluator.doclib.metadata.factura.emitida</evaluator>
</action>


detailSendingeInvoice.get.js

<javascript>
var connector = remote.connect("alfresco");
var data = connector.get("/emfradetail?nodeId=e2c2eca2-d54b-4584-a182-f33d55c6bd3f");

if (result.status != status.STATUS_OK)
{
   status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Unable to call emfradetail data webscript. " +
                  "Status: " + result.status + ", response: " + result.response);
   return null;
}

var result = eval('(' + data + ')');
model.fradetail = result["fradetail"];
model.emfradetail = result["emfradetail"];
</javascript>

detailSendingeInvoice.get.desc.xml


<webscript>
   <shortname>Detalle facturas emitidas</shortname>
   <description>Muestra el detalle de los envíos de las facturas emitidas</description>
   <url>/components/emfra/detailSendingeInvoice?nodeId={nodeId}</url>
</webscript>


When I click on the link in the document menu, Share returns an error:

javax.servlet.ServletException: Could not resolve view with name 'site/empresa-1/components/emfra/detailSendingeInvoice' in servlet with name 'Spring Surf Dispatcher Servlet'

Can anyone guide me to solve this?

Thanks a lot in advance,
6 REPLIES 6

mitpatoliya
Star Collaborator
Star Collaborator

agey
Champ in-the-making
Champ in-the-making
Hi mitpatoliya, thanks for your help. I am using an Alfresco 4.2 version so I can't use the guide that you indicated me:

IMPORTANT
The procedures outlined below are for Share v3.x only and should not be used for v4.0 and newer.

I have a webscript in Alfresco that get data and show in a json page:

emfradetail.get.desc.xml


<webscript>
   <shortname>EmFra Detail</shortname>
   <description>Retrieve detail of sendings from node id</description>
   <url>/emfra/emfradetail?nodeId={nodeId}</url>
   <format default="json">argument</format>
   <authentication>user</authentication>
   <transaction>required</transaction>
</webscript>


emfradetail.get.json.ftl


{

"fradetail" : [

   "numFra" : "${numFra}",
   "docId" : "${docId}",
   "fechafra" : "${fechafra}"
   
]
   
"emfradetail" : [

<#list detalle as detail>
{

   "user" : "${detail.user}"

   "enviado" : "${detail.enviadoString}",
   
   <#if detail.enviado>

       "fechaEnviado" : "${detail.fechaEnviado}" ,
   
    </#if>
   
    "email" : "${detail.email}",
 
    "descargada" : "${detail.descargadaString}",
   
    <#if detail.descargada>

         "fechaDescargada" : "${detail.fechaDescargada}"
      
      </#if>
}
</#list>
]
}


This webscript works fine. Now I want to call it from document menu action, retrieve data from json result and display it in a page or popup. I configured an action in share-config-custom.xml:


<action id="sm.doclib.action.detail.sending.e-invoices"
                    icon="detailed-view-on"
                    type="pagelink"
                    label="actions.document.detail.sending.e-invoice">
   <param name="page">/components/emfra/detailSendingeInvoice?nodeRef={node.nodeRef}</param>
   <evaluator>evaluator.doclib.metadata.invoice.sent</evaluator>
</action>

<actionGroup id="document-browse">
   <action index="121" id="sm.doclib.action.detail.sending.e-invoices" label-id="actions.document.detail.sending.e-invoice"/>
</actionGroup>


The action link is display in document menu. This is the webscript executed:

detailSendingeInvoice.get.desc.xml


<webscript>
   <shortname>eInvoice detail</shortname>
   <url>/site/{site}/components/emfra/detailSendingeInvoice?nodeRef={nodeRef}</url>
</webscript>


detailSendingeInvoice.get.js


<import resource="classpath:/alfresco/templates/org/alfresco/import/emfra-util.js">

function main()
{
   EmfraUtil.param('nodeRef');
   var detail = EmfraUtil.getSendingeInvoiceDetail(model.nodeRef);
   if (detail)
   {
      model.fradetail = detail["fradetail"];
           model.emfradetail = detail["emfradetail"];
   }
}

main();


emfra-util.js


<import resource="classpath:/alfresco/site-webscripts/org/alfresco/components/documentlibrary/data/surf-doclist.lib.js">

var this_EmfraUtil = this;

var EmfraUtil =
{
   getSendingeInvoiceDetail: function getSendingeInvoiceDetail(nodeRef){
      if (nodeRef){
         var url = '/emfra/emfradetail?nodeId=' + nodeRef;
           
      }
      var result = remote.connect("alfresco").get(url);
      if (result.status == 200){
           var details = eval('(' + result + ')');
           if (details && (details.item || details.items)){
               return details;
           }
      }
      return result.status;
   },
        param: function param(name, defaultValue)
         {
            var value;
            if (args[name] && args[name].length != 0)
            {
               value = args[name];
            }
            else if (this_EmfraUtil.hasOwnProperty("page") && page.url.args[name] && page.url.args[name].length != 0)
            {
               value = page.url.args[name];
            }
            else if (this_EmfraUtil.hasOwnProperty("page") && page.url.templateArgs[name] && page.url.templateArgs[name].length != 0)
            {
               value = page.url.templateArgs[name];
            }
            else if (this_EmfraUtil.hasOwnProperty("template") && template.properties[name] && template.properties[name].length != 0)
            {
               value = template.properties[name];
            }
            else if (arguments.length > 1)
            {
               value = defaultValue;
            }
            else
            {
               EmfraUtil.error(400, 'Parameter "' + name+ '" is missing.', true);
            }
            model[name] = value;
            return value;
         },
        
         error: function error(code, message, redirect)
         {
            status.code = arguments.length > 0 ? 500 : code;
            status.message = message || 'An error occured';
            status.redirect = arguments.length > 2 ? redirect : true;
            throw new Error(message);
         },     
}


When user click on action link, it returns an error:

   org.springframework.extensions.webscripts.WebScriptException - 02200002 Failed to execute script 'classpath*:alfresco/site-webscripts/org/sm/components/emfra/detailSendingeInvoice.get.js': null

I don't know what is wrong. Can you guide me how to fix it?

Thanks

agey
Champ in-the-making
Champ in-the-making
I'm trying detailSendingeInvoice.get.js code in Javascript console:


<import resource="classpath:/alfresco/templates/org/alfresco/import/veritas-util.js">
function main()
{
   var detail = VeritasUtil.getSendingeInvoiceDetail(model.nodeRef);
   if (detail)
   {
      model.fradetail = detail["fradetail"];
           model.emfradetail = detail["emfradetail"];
   }
}
main();


After a few modifications to debug the code, it returns this error:

500 Internal Error An error inside the HTTP server which prevented it from fulfilling the request. 02200002 Wrapped Exception (with status template): 02200033 Failed to execute script 'Javascript Console Script': 02200032 ReferenceError: "remote" is not defined. (577418f4f2d1b88660674699ef2f5bb3.js#13)

Any ideas?

mitpatoliya
Star Collaborator
Star Collaborator
This error,

org.springframework.extensions.webscripts.WebScriptException - 02200002 Failed to execute script 'classpath*:alfresco/site-webscripts/org/sm/components/emfra/detailSendingeInvoice.get.js': null

indicating that your script file is not available on classpath.
where you are placing those files?

agey
Champ in-the-making
Champ in-the-making
The detailSendingeInvoice.get.js file is in alfresco\site-webscripts\org\sm\components\emfra into a jar file. In the same folder are also detailSendingeInvoice.get.desc.xml and detailSendingeInvoice.get.html.ftl files.

When I click in the action link it goes to url http://localhost:8081/share/page/site/empresa-1/components/emfra/detailSendingeInvoice?nodeRef=works... and display the error.

Thank you,

mitpatoliya
Star Collaborator
Star Collaborator
To answer your last problem.
Javascript console does not have that remote object available in its execution environment so you are getting the error.