cancel
Showing results for 
Search instead for 
Did you mean: 

Looking up node references in Share forms

mcox
Champ in-the-making
Champ in-the-making
I am trying to display a category field as text in a Share Freemarker form context (actually an adapted version of category.ftl control).

I can easily display the node reference of a category field using ${field.value?html} which displays as:

workspace://SpacesStore/1d5b8f4a-a2a7-11dc-8d74-6f45f39984e5


but don't know how to translate that into human readable category text.

The general Alfresco Freemarker documentation includes this example:

${companyhome.nodeByReference["workspace://SpacesStore/e661dccb-ecc0-11da-9974-63f65406985a"].id}


However, companyhome doesn't appear to be present in the forms context. If I try to use it I get the Freemarker error "Expression companyhome is undefined".

Does anyone know how to look up the category properties from its nodeRef in Share forms and form controls, or can point me to docs on the root objects and methods available to Freemarker in these contexts?

Thanks
3 REPLIES 3

jpfi
Champ in-the-making
Champ in-the-making
Hi,
one way to solve your requirement is to add a XHR-Request to your Repository when the browser renders the form control, e.g.

<div class="form-field">
   <div class="viewmode-field">
      <span class="viewmode-label">${field.label?html}:</span>
      <span class="viewmode-value" id="${fieldHtmlId}-value">${field.control.params.displayValue}</span>
      <input type="hidden" name="${field.name}" id="${fieldHtmlId}-hidden" />
   </div>
</div>
<script type="text/javascript">//<![CDATA[
(function()
{
   YAHOO.util.Event.onContentReady("${fieldHtmlId}-hidden", function ()
         {
            var element = YAHOO.util.Dom.get("${fieldHtmlId}-hidden");
              element.value = "";
             
              // define success handler
               var successHandler = function PreselectCategory_successHandler(response)
               {
                  //your code…
                  element.value = response.json.data.name;
               };
              
               // define failure handler
               var failureHandler = function PreselectCategory_failureHandler(response)
               {
                 //your code…
                 
               };
              
                var url = Alfresco.constants.PROXY_URI + "your repo webscript url");
               // call the webscript
             var config =
             {
                method: "GET",
                url: url,
                successCallback:
                {
                   fn: successHandler,
                   scope: this
                },
                failureCallback:
                {
                   fn: failureHandler,
                   scope: this
                }
             };
             Alfresco.util.Ajax.request(config);
         }, this);
   
})();
//]]></script>


Cheers, Jan

zladuric
Champ on-the-rise
Champ on-the-rise
<strong>companyhome</strong> is a root-scoped object for freemarker, but not in Share context - it's in Alfresco. What you could do is:
a) add a call to backend like Jan said - you could even use an existing Alfresco webscript to get the node data. Do the XHR request (which basically makes a call to Alfresco backend) and put this as URL:
url = Alfresco.constants.PROXY_URI + 'slingshot/doclib/categorynode/node/workspace/SpacesStore/28d678b8-966c-4328-b11c-3a8157de87b4'


You get a response JSON with category items there, something like <blockquote>{
   "totalResults": 4,
   "items":
   [
      {
         "nodeRef": "workspace://SpacesStore/a042e5de-269b-4dd5-ab67-7156da1246e8",
         "name": "Languages",
         "description": "",
         "hasChildren": true,
         "userAccess":
         {
            "create": true,
            "edit": true,
            "delete": true
         }
      },
      {
         "nodeRef": "workspace://SpacesStore/02547532-80ca-445f-be4b-32a2cd8b171d",
         "name": "Regions",
         "description": "",
         "hasChildren": true,
         "userAccess":
         {
            "create": true,
            "edit": true,
            "delete": true
         }
      },
      {
         "nodeRef": "workspace://SpacesStore/59c18b84-e358-460f-8bbd-7809f80e4704",
         "name": "Software Document Classification",
         "description": "",
         "hasChildren": true,
         "userAccess":
         {
            "create": true,
            "edit": true,
            "delete": true
         }
      },
      {
         "nodeRef": "workspace://SpacesStore/b3412301-942e-4ef0-b74b-0c56c6f93f7c",
         "name": "Tags",
         "description": "",
         "hasChildren": false,
         "userAccess":
         {
            "create": true,
            "edit": true,
            "delete": true
         }
      }
   ]
}</blockquote>

b) Another option would be to override the Share component you're using so that its controller generates request to the backend (before the page renders) and then it can put the requested data in the model so Freemarker can use it.

mcox
Champ in-the-making
Champ in-the-making
Thanks for these replies. Is there any on-line documentation available on XHR requests and how to use them from within Freemarker?