cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve properties description via Javascript

kitelabs
Champ in-the-making
Champ in-the-making
Hi guys,
I need help to retrieve properties descriptions as specified in my customModel.xml

In my model I have something like that:

……….

        <property name="fa:customer">
           <title>Customer Name</title>
           <type>d:text</type>
           <mandatory>true</mandatory>
           <index enabled="true">
                  <atomic>false</atomic>
                  <stored>false</stored>
                  <tokenised>true</tokenised>
           </index>
        </property>
……..
Now I need to retrieve the string "Customer Name" between  <title></title> tag.
Using a simple webscript, I am able to get the full list of properties for a desired document in this way:

documentprops.get.desc.xml
<webscript>
<shortname>Document Properties</shortname>
<description>It provides document’s property</description>
<url>/sample/documentprops?nodeRef={nodeRef}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>none</transaction>
</webscript>

documentprops.get.js
 var query = "@sys\\:node-uuid:" + "\"" + args.nodeRef + "\"" + " AND TYPE:\"cm:content\"";
var results = search.luceneSearch(query);
model.document = results[0];

and the .ftl is:

documentprops.get.json.ftl
{
"properties" : [
<#assign props = document.properties?keys>
<#list props as t>
{
    <#– If the property exists –>
    <#if document.properties[t]?exists>
       <#– If it is a date, format it accordingly–>
       <#if document.properties[t]?is_date>
       "${t}": "${document.properties[t]?string("yyyy-MM-dd")}"
       <#– If it is a boolean, format it accordingly–>
       <#elseif document.properties[t]?is_boolean>
       "${t}": "${document.properties[t]?string("yes", "no")}"
       <#– Otherwise treat it as a string –>
       <#else>
       "${t}": "${document.properties[t]}"
       </#if>
    </#if> }
    <#if t_has_next>,</#if>
</#list>
]
}
In this way, I can get the full list pointing to the url http://localhost:8080/alfresco/service/sample/documentprops?nodeRef=beb21716-f5f0-421a-a366-2f0cf85a...
but I need to get, for each property, the label as assigned into model file ("Customer Name" in this case).

I can get, for example:
…..
"{http://www.kitelabs.it/model/content/1.0}customer": "DELL MAROCCO"
……

So the property name is "{http://www.kitelabs.it/model/content/1.0}customer" and the property value is "DELL MAROCCO"

I would like to know if there is a way to obtain the property description (or property label or displayName I don't know what is the right name) corresponding to "Customer Name".

Thanks in Advance
4 REPLIES 4

abarisone
Star Contributor
Star Contributor
Hi,
here you can find more info about Javascript API, especially related to properties: http://wiki.alfresco.com/wiki/4.0_JavaScript_API#ScriptNode_API
Usually I use this code to get properties:
properties:<#list node.properties?keys as t>
            <#– If the property exists –>
                <#if (node.properties[t]?exists) )>
                   <#– If it is a date, format it accordingly–>
                   <#if node.properties[t]?is_date>
                          ${t}:"${node.properties[t]?string("dd-MM-yyyy")}"
                   <#– If it is a boolean, format it accordingly–>
                   <#elseif node.properties[t]?is_boolean>
                          ${t}:"${node.properties[t]?string("yes", "no")}"
                   <#– If it is a sequence–>
                   <#elseif node.properties[t]?is_sequence>
                          ${t}:[<#list node.properties[t] as item>
                                ${item}<#if item_has_next>,</#if>
                            </#list>]
                   <#– Otherwise treat it as a string –>
                   <#else>
                           ${t}:"${node.properties[t]?js_string}"
                   </#if>
                   <#if t_has_next>,</#if>
                </#if>
             </#list>

P.S.: please use code tags to make your code more readable… Smiley Very Happy

Regards,
Andrea

kitelabs
Champ in-the-making
Champ in-the-making
Hi Andrea,
thanks for your answer.
I've already visited this url:  http://wiki.alfresco.com/wiki/4.0_JavaScript_API#ScriptNode_API and your code is similar to mine, although better formatted  Smiley Very Happy

The point is that in both cases we got a list of pairs of property name  and property value, instead of property description.

It seems that we can refer to the single property as:


var p1 = document.properties.name
var p2 = document.properties["name"];

for the properties that belongs to the cm:namespace

or:


var p3 = document.properties["my:property"];
var p4 = document.properties["{http://my.domain.org/model/content/1.0}property"];

on the other cases.

But the question is: there is a way to get the property description ?

In our code, the line:

${t}:"${node.properties[t]?js_string}"

give us, for example something like:

"{http://my.domain.org/model/content/1.0}property": "the quick brown fox jumps over the lazy dog"

but when I set the property , in the model file, I gave it a title, for example "Short Rhyme"..  well now I would like to get that string.

I hope I was more clear with my question.

Regards

Marcello

abarisone
Star Contributor
Star Contributor
Hi,
perhaps this post could be useful https://forums.alfresco.com/en/viewtopic.php?f=5&t=46716

Regards,
Andrea

kitelabs
Champ in-the-making
Champ in-the-making
Hi Andrea,

thanks again, I know that it should be possible to retrieve the property description writing the right Java code, but I would get one solution in Javascript environment.
Sincerely, I don't think that my problem is too big to require an Alfresco guru like Jeff Potts   😉
If you have to design, suppose,  one client to access certain documents, you would like to inherit the definitions already made ​​in the model file, in which you can find, for example,  the data type and the description of each property.

I hope that someone will have a nice solution to solve my problem.

Regards

Marcello