The first part of this script seems to work correctly, it iterates through every document and if the document name matches a particular regex pattern, it it gives it a specific variable to be utilized later in the script.
However, at the end of the script when I attempt to us whether or not a variable exists as a condition for an if statement, things don't evaluate true or false as expected. What am I doing wrong here?
// iterate through all docs assigning variables to templates and art
for (i = 0; i < documents.length; i++) {
var curDoc = app.activeDocument = app.documents[i];
var curDocNoExt = curDoc.name.split(".");
var workingName = curDocNoExt[0];
if (workingName.match(/^\d{5,6}$/) != null) {
var frontArt = app.documents[i];
var targetName = frontArt.name
} else {
if (workingName.match(/^\d{5,6}(b))$/) != null) {
var backArt = app.documents[i];
var backToggle = 1;
} else {
if (workingName.match(/^fkeep$/) != null) {
var frontTemp = app.documents[i];
} else {
if (workingName.match(/^fxkeep$/) != null) {
var frontSquare = app.documents[i];
} else {
if (workingName.match(/^bkeep$/) != null) {
var backTemp = app.documents[i];
} else {
if (workingName.match(/^bxkeep$/) != null) {
var backSquare = app.documents[i];
}
}
}
}
}
}
}
//use variables to do stuff!
if (backArt != null) {
app.activeDocument = backTemp;
var namedBackTemp = backTemp.duplicate(targetName + "B");
}