Increment
Increment file name
function ProcessDocument(doc) { var oldDocPath = doc.filePath.absoluteURI; var newDocFile = new File(oldDocPath + "/Backup_" + doc.name); if (newDocFile.exists) { // Don't overwrite existing files var increment = 1; while (newDocFile.exists) { newDocFile = new File(oldDocPath + "/Backup" + "(" + increment++ + ")_" + doc.name); } } doc.fullName.copy(newDocFile.absoluteURI); }
Increment layer name
var layerName = topicName; var layer = doc.layers.item(layerName); if (layer != null) { var increment = 1; while (layer != null) { layerName = topicName + " (" + increment++ + ")"; layer = doc.layers.item(layerName); } } layer = doc.layers.add({name: layerName});