cancel
Showing results for 
Search instead for 
Did you mean: 

Create new Serie using Javascript

jordiv
Champ on-the-rise
Champ on-the-rise
Hello,

I'm trying to create a new record series in the Javascript console for testing purposes (later I want to use it in a web script).

The series gets created, but the problem is that I can't create new categories inside the series I've created (the "New Category" button is disabled).


var filePlan = companyhome.childByNamePath(space.name + "/rm/documentLibrary");
var series = filePlan.children;

var newSeries = filePlan.createFolder("Test folder");

newSeries.addAspect("{http://www.alfresco.org/model/rmcustom/1.0}customRecordSeriesProperties");
newSeries.addAspect("{http://www.alfresco.org/model/content/1.0}titled");
newSeries.addAspect("{http://www.alfresco.org/model/recordsmanagement/1.0}filePlanComponent");
newSeries.addAspect("{http://www.alfresco.org/model/recordsmanagement/1.0}recordComponentIdentifier");

Anyone knows what I'm missing?

Thanks,
Jordi.
3 REPLIES 3

jordiv
Champ on-the-rise
Champ on-the-rise
It seems that I've found a workaround to my problem, based on this post.

Rather than creating a new folder, I copy an existing record series and then I change it's name and metadata:

var filePlan = companyhome.childByNamePath(space.name + "/rm/documentLibrary");
var series = filePlan.children;
var templateSeries = series[0];

if (templateSeries != null) {
  var newSeries = templateSeries.copy(filePlan, false);
  newSeries.name = "Test folder";
}

If there's a better way to do this or someone knows why the code from my first post doesn't work feel free to reply.


Cheers,
Jordi.

jm_pascal
Star Contributor
Star Contributor
Hi,

You are wrong because it's not a cm:folder node, It's dod:recordSeries node.

Behind you can find a snippet to do what you except.


var filePlan = companyhome.childByNamePath("Sites/rm/documentLibrary");

if (filePlan != undefined){
  var testSerie = createSeries(filePlan, "S123456");
}

function createSeries(folder, name){
  if (folder.childByNamePath(name) != undefined){
    return folder.childByNamePath(name);
  }
 
  var series = folder.createNode(name, "dod:recordSeries");
 
  series.addAspect("rma:filePlanComponent");
 
  //Unique Identifier
  var props = new Array(1);
  props["rma:identifier"] = createUniqueIdentifier(series);
  series.addAspect("rma:recordComponentIdentifier", props);
 
  return series;
}

function createUniqueIdentifier(serieNode){
  //Unique Identifier
  var d = new Date();
  var year = d.getFullYear();
  var dbid = serieNode.properties["sys:node-dbid"] + "";
  var recordId = year + "-" + padString(dbid, 10);
  return recordId;
}

//Create Unique Identifier
function padString(s, len){
  var result = s;
  for (i = 0; i < (len - s.length); i++){
    result = "0" + result;
  }
  return result;
}

Hope it helps

jordiv
Champ on-the-rise
Champ on-the-rise
Thanks a lot, it works like a charm!  Smiley Happy


Cheers,
Jordi.