cancel
Showing results for 
Search instead for 
Did you mean: 

accessing content model in javascript.

lmanoh
Champ in-the-making
Champ in-the-making
Hi,
Hi im new to alfresco. how can we access the Node refference by using java script.

i download source file from Alfresco SVN. i modified something. i that i need access the costom content model  by using the java script. i read that alfresco API available. but i dont know.. how to use that directly with our code.

var name=person.properties.userName

here,  person not identified as an object.  how can we exceute this code in java script.

please anyone help me

-lenin.
5 REPLIES 5

jbarmash
Champ in-the-making
Champ in-the-making
The content model you define should automatically be available to the JavaScript.  For the example you mention, it should probably be something closer to:

var name=person.properties["userName"];

Take a look at a few script examples in Data Dictionary for inspiration. 


There are also some good examples in JavaScript Cookbook:

http://wiki.alfresco.com/wiki/JavaScript_API_Cookbook

lmanoh
Champ in-the-making
Champ in-the-making
thanks  jbarmash,

The problem is person object is not regaganised. it shows  like unidentified object person, can 't be resolved.
shall i need to include any packages to execute this special  Javascript API ?
i have been called method in onclick function in document-details.jsp. its been called, but not execute the javascript stattement like 
var name=person.properties["userName"];

it would be a greate help.! thanks in advance.
-Lenin

jbarmash
Champ in-the-making
Champ in-the-making
I think i understand the source of confusion here.  There are two types of JavaScipt that are possible - serverside javascript and client side.  I thought you were talking about server side, where the person object should be available, and it seems like you are talking about client side.  In that case, the person object is not available unless you make it available. 

In 3.0, there is a REST API which you could call from your client-side javascript in order to get the data you need (many of these web scripts return JSON, so it should be quite easy). 
  http://wiki.alfresco.com/wiki/Repository_RESTful_API_Reference
  http://wiki.alfresco.com/wiki/3.0_REST_API

Pre 3.0, there is no standard API available, but you could write one yourself to expose the person object through web scripts (possibly even backport some of the webscripts from 3.0).

mpeters
Champ in-the-making
Champ in-the-making
The content model you define should automatically be available to the JavaScript.  For the example you mention, it should probably be something closer to:

var name=person.properties["userName"];

What is the easiest way to get more informations about the available properties of a certain content model, e.g. "person"? Or to be more precise: how do I know, which  properties a certain content model has?

Kind regards
Markus

openpj
Elite Collaborator
Elite Collaborator
Now I think that the Javascript API of Alfresco doesn't expose any methods for that.

For the Javascript API you can expose the DictionaryService of Alfresco extending the Mozilla Rhino engine:
http://wiki.alfresco.com/wiki/3.4_JavaScript_API#Adding_Custom_Script_APIs

In this way you have to extend the Alfresco Javascript API with a new Javascript object available in the scope of the script that is the following service:
http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/dictionary/Dictionary...

As you can see the DictionaryService allows you to get all the information that you need  :wink:

Hope this helps.