cancel
Showing results for 
Search instead for 
Did you mean: 

javascript reading aspect cm:attachments and also check the mimetype of some file and create from folder if plain/text

hdalang
Champ in-the-making
Champ in-the-making
OK, the mimetype is working in my code so my problem is that I want to read attachment of my file, please help me doing that


var fileNames = space.children;

function main(){
  for (i=0; i<fileNames.length; i++){
    logger.log(fileNames.properties.content.mimetype);
    if(fileNames.isDocument && (fileNames.properties.content.mimetype).equals("text/plain")){
      //document.childAssocs
      var fileAttachments = fileNames.assocs['cm:attachments'][1];
      logger.log(i+" - "+fileNames.assocs['cm:attachments']);
    }
  };
/*
  for (i=0; i<fileAttachments.length; i++){
    logger.log("===================================================");
    logger.log(fileAttachments);
  };
*/
}
main();
1 REPLY 1

hdalang
Champ in-the-making
Champ in-the-making
I have found solution for this:

var fileName = space.children;
function main(){
  for (i=0; i<fileName.length; i++){
    if(fileName.isDocument && (fileName.properties.content.mimetype).equals("text/plain")){
      logger.log(fileName.properties.name);
      var fileAttachments = fileName.assocs['cm:attachments'];
      var spaceName = space.createFolder(fileName.properties.name+" -email");
      var backupFolder = space.childByNamePath(spaceName.properties.name);
      fileName.move(backupFolder);
      var myFolder = space.children; 
      for ( var j in fileAttachments){
         logger.log(fileAttachments[j].name);
        for(x=0; x<myFolder.length; x++){
          if((myFolder[x].properties.name).equals(fileAttachments[j].name)){
           (myFolder[x]).move(backupFolder);
            break;
          }
        }
      };
      break;
    }
  };
}
main();