cancel
Showing results for 
Search instead for 
Did you mean: 

change model with script

gokceng
Champ in-the-making
Champ in-the-making
What is the solution to add a new aspect or a property to an active model via javascript?
8 REPLIES 8

invictus9
Champ in-the-making
Champ in-the-making
Consult the Javascript API on the Alfresco wiki. It has a list of functions that can be called from Javascript to affect the node repository.

You can specialize a content type (change to a subtype) by using node.specializeType("my:newsubtype"). You can also use node.addAspect("my:newAspect").

gokceng
Champ in-the-making
Champ in-the-making
Consult the Javascript API on the Alfresco wiki. It has a list of functions that can be called from Javascript to affect the node repository.

You can specialize a content type (change to a subtype) by using node.specializeType("my:newsubtype"). You can also use node.addAspect("my:newAspect").

I think I couldn't explain my problem, sorry. I want to change the model, not the nodes. In fact, model is a node too, so can I change the content of model just like other nodes?

tommorris
Champ in-the-making
Champ in-the-making
Hi there,

With regards to reading the model from Javascript:
You need the capabilities of the Dictionary Service (http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/dictionary/Dictionary...). As far as I know, this isn't available through the Javascript API, but I would recomend following this thread to get what you want:
http://forums.alfresco.com/en/viewtopic.php?f=36&t=21010

But when it comes to manipulating the model - see if this reference meets your needs:
http://wiki.alfresco.com/wiki/Dynamic_Models

I hope this helps.

Tom
http://www.ixxus.com

gokceng
Champ in-the-making
Champ in-the-making
Thanks for your reply.
I've looked at the function defined in DictionaryService. I couldn't find setter methods. Do you know if that example works:

AspectDefinition aD = dictionaryService.getAspect(MyModel.MyAspect);
ad = new AspectDefinition();

Because it says AspectDefinition is read only…

gokceng
Champ in-the-making
Champ in-the-making
I've found a solution, send the new content model from client side -in my situation it is flex- and set the model's content to this. And it worked…

shea
Champ in-the-making
Champ in-the-making
Does anyone has a working example for this?
I am new to Alfresco and trying to get it to work.
My javaScript looks like this:
                …
   var someFolder = rootFolder.createFolder("New Folder");
   someFolder.addAspect("custom:someAspect");

I was able to create a "New Folder", but the aspect was not added to the "New Folder" by the above code.
I can add the "someAspect" to the "New Folder" manually using Alfresco Explorer.

Appreciate any help that I can get.  Thanks

rrobles
Champ in-the-making
Champ in-the-making
I have the same problem.
Before I have this model

<type name="ct:customFolder">
         <title>Custom</title>
         <parent>cm:folder</parent>
         <properties>
            <property name="ct:code">
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
            <property name="ct:year">
               <type>d:int</type>
               <mandatory>true</mandatory>
               <constraints>
               <constraint ref="ct:yearValidate"/>
                </constraints>
            </property>
         </properties>
         <mandatory-aspects>
             <aspect>ct:customAspect</aspect>
             </mandatory-aspects>
        </type>
And now I need change my model and add a new aspect,

<type name="ct:customFolder">
         <title>Custom</title>
         <parent>cm:folder</parent>
         <properties>
            <property name="ct:code">
               <type>d:text</type>
               <mandatory>true</mandatory>
            </property>
            <property name="ct:year">
               <type>d:int</type>
               <mandatory>true</mandatory>
               <constraints>
               <constraint ref="ct:yearValidate"/>
                </constraints>
            </property>
         </properties>
         <mandatory-aspects>
             <aspect>ct:customAspect</aspect>
                            <aspect>ct:newAspect</aspect>
         </mandatory-aspects>
        </type>
The problem is in the folders created with my old model.
I tried to create a script like you but I have the same problem, the folder node can't allow the function AddAspect,
Anyone know other way of to do it?
Thanks

rrobles
Champ in-the-making
Champ in-the-making
I found other way to do it. I used an action in my  script and it works.


  var addAspect = actions.create("add-features");
  addAspect.parameters["aspect-name"] = "ct:newAspect";
  nodes = search.luceneSearch("TYPE:\"ct:customFolder\"");
  for each (var node in nodes)
  {
      addAspect.execute(node);
  }
 

I don't know if this solution is the best but it works