AnsweredAssumed Answered

Copy node without properties

Question asked by sysoncloud on Apr 9, 2015
Latest reply on Apr 17, 2015 by iblanco
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

Outcomes