cancel
Showing results for 
Search instead for 
Did you mean: 

Copy node without properties

sysoncloud
Champ in-the-making
Champ in-the-making
Actually I have two questions.

1. Copy node problem.
var newNode = srcNode.copy(srcNode.parent);

all the properties copied from source also, is there a way just copy the file but not properties (meta-data)?
then I have to set the new node properties like this:

newNode.properties.title = "title";
newNode.properties.description = "desc";
newNode.save()

but the new node's title and description remains <strong>unchanged</strong>, it is still same as the source node, why?


2. Query with date problem.
I have a lots records and need to search using lucene.
I think out a way that loop 1000 records every time according to modified date.
(i know can off 1000 limits but it's too slow and probably has no response)

the next loop start from previous modified node, but if I didnot change the date it will throws error.


var query = 'PATH:"/app:company_home/app:guest_home/cm:Test//*"';
var sort1 =   {
     column: "@{http://www.alfresco.org/model/content/1.0}modified",
     ascending: true  
};
var paging =   {
     maxItems: 1000,
     skipCount: 0  
};
var def = {
     query: query,
     language: "lucene",
     sort: [sort1],
     page: paging  
};

var nodes = search.query(def);
while(nodes.length > 0) {   
    for(var i=0;i<nodes.length;i++) {
        // do sth
    }

    var prevModified = nodes[nodes.length - 1].properties.modified;
   
    // weird, must add one day, otherwise throws Node does not exist, but this may skip some doc !
    prevModified.setDate(prevModified.getDate() + 1);
   
    var fromDate = prevModified.getFullYear() + '-' + (prevModified.getMonth()+1) + '-' + prevModified.getDate();
    var dateRange = ' AND (@cm\\:modified:[' + fromDate + ' TO NOW])';
    def.query = query + dateRange;
    nodes = search.query(def);
}


the problem is I found from second loop, if the query date occurs <strong>between</strong> previous date range, then it will throws <em>Node does not exist !</em>
so I have to change the prevModified by add one day to out of that range, how to solve this?

Thanks
1 REPLY 1

iblanco
Confirmed Champ
Confirmed Champ
Did you try to just create a new "empty" node and then just assign the content like this:


newNode.content = srcNode.content;


In Java setting the content just like a regular property works, but not sure if it does for Javascript.

And did you try this:


newNode.addAspect("cm:titled");

newNode.properties["cm:title"] = "title";
newNode.properties["cm:description"] ="description";

newNode.save();


In Alfresco 4.2 aspects are added automatically when a property that uses them is added but not sure if this used to work like so in Alfresco 3.4.