Page 1 of 1

hierarchy path

Posted: Fri Nov 27, 2015 4:10 pm
by kmcrae
Hi,

how can use hierarchy path with three first digit (is the page number) of file for download on the good folder match?!!

101_CAT2016_CLUB_FRNET.pdf ------> CAT16_CX_ANDET_MachineConsumables_100-118
102_CAT2016_CLUB_FRNET.pdf ------> CAT16_CX_ANDET_MachineConsumables_100-118

228_CAT2016_CLUB_FRNET.pdf ------> CAT16_CX_ANNET_OfficeSupplies_209-262
229_CAT2016_CLUB_FRNET.pdf ------> CAT16_CX_ANNET_OfficeSupplies_209-262


Help Thank!!

Re: hierarchy path

Posted: Fri Nov 27, 2015 4:17 pm
by sander
I'm not quite sure what you mean.

Do you want to move e.g. the file 101_CAT2016_CLUB_FRNET.pdf to folder CAT16_CX_ANDET_MachineConsumables_100-118?

And due to 101 in the filename, it is in range 100-118 and needs to be moved to that folder? Correct?

Re: hierarchy path

Posted: Fri Nov 27, 2015 4:29 pm
by kmcrae
yes that i want!!

Re: hierarchy path

Posted: Fri Nov 27, 2015 4:40 pm
by sander
Is there a way to indentify the destination folder, is it somehow attached as metadata to the file?

If not, I'll go for a script expression in your path segment, which will check if the first 3 digits in the filename are 101 to 118 then set path segment to CAT16_CX_ANDET_MachineConsumables_100-118, if 228-262 set to CAT16_CX_ANNET_OfficeSupplies_209-262 etc.

But, in my opinion, this is only good manageable if these folders don't change (e.g. for every order) and there's not a couple of 100 of them.

Re: hierarchy path

Posted: Fri Nov 27, 2015 4:59 pm
by kmcrae
the best solution is the script expression but i don't no create the script!? can you with the script?

Re: hierarchy path

Posted: Sun Nov 29, 2015 1:07 pm
by sander
Use this as your script expression in your Set hierarchy path;

Image

Code: Select all

// Set first three charachters of jobName as variable pageNumber
var pageNumber		= job.getVariableAsNumber("[Job.Name:Segment=\"1-3\"]");

// Default path is Unknown, in case of non defined
var hierarchyPath		= "Unknown";

switch (true) {
	case (pageNumber >= 100 && pageNumber <= 118):    				// Check if pageNumber is equal or greater than 100, and equal or less than 118
	hierarchyPath = "CAT16_CX_ANDET_MachineConsumables_100-118";	// Set path to CAT16_CX_ANDET_MachineConsumables_100-118
	break;
	
	case (pageNumber >= 209 && pageNumber <= 262):					// Same here, check if pageNumber is equal or greater than 209, and equal or less than 262
	hierarchyPath = "CAT16_CX_ANNET_OfficeSupplies_209-262";  		// Set path to CAT16_CX_ANNET_OfficeSupplies_209-262
	break;
}

hierarchyPath;
Result:
Image

Hope it helps,

Re: hierarchy path

Posted: Mon Nov 30, 2015 9:45 pm
by kmcrae
WOW its work and with this sample script enlighten me in my learning!! thank!

Re: hierarchy path

Posted: Mon Nov 30, 2015 10:04 pm
by sander
No problem, glad I could help you out!

Re: hierarchy path

Posted: Tue Dec 01, 2015 1:35 pm
by sander
Hm, somehow I copied a slightly different code as I wanted it to be.

Code: Select all

// Set first three charachters of jobName as variable pageNumber
var pageNumber		= job.getVariableAsNumber("[Job.Name:Segment=\"1-3\"]");
var hierarchyPath;


switch (true) {
	case (pageNumber >= 100 && pageNumber <= 118):    				// Check if pageNumber is equal or greater then 100, and equal or less then 118
	hierarchyPath = "CAT16_CX_ANDET_MachineConsumables_100-118";	// Set path to CAT16_CX_ANDET_MachineConsumables_100-118
	break;
	
	case (pageNumber >= 209 && pageNumber <= 262):					// Same here, check if pageNumber is equal or greater then 209, and equal or less then 262
	hierarchyPath = "CAT16_CX_ANNET_OfficeSupplies_209-262";  		// Set path to CAT16_CX_ANNET_OfficeSupplies_209-262
	break;
	
	default:
	hierarchyPath		= "Unknown";										// Default path is Unknown, in case of non defined
	break;
}

hierarchyPath;
Added default: in the switch case, so it defaults the 'correct' way.

Re: hierarchy path

Posted: Tue Dec 01, 2015 5:39 pm
by bens
That's an interesting use of a switch statement. Any reason you don't use an if/else?

Code: Select all

var pageNumber = job.getVariableAsNumber("[Job.Name:Segment=\"1-3\"]");
var hierarchyPath = "Unknown";

if (pageNumber >= 100 && pageNumber <= 118)
    hierarchyPath = "CAT16_CX_ANDET_MachineConsumables_100-118";
else if (pageNumber >= 209 && pageNumber <= 262)
    hierarchyPath = "CAT16_CX_ANDET_MachineConsumables_100-118";

hierarchyPath;

Re: hierarchy path

Posted: Tue Dec 01, 2015 8:59 pm
by sander
Not really, based on my experience so far.
My Switch experience, and with that Javascript / Switch scripting, is nearly over a year by now. Once when I had to do a compare with like 10 values I came up with the thoughts it is not efficient to check e.g. 9 if's before I reach if 10. That's why I used switch. It looked faster to me, however since I am learning through reading the manual and minimalize Googling scripting solutions it might not be the best way.
So all based on my own logic, and with this topic issue I notice, by automatism, I go with switch right away. If, else if, it doesn't sound bad in this case haha.

In this particular case, the only other thing I can lie off; I think it's better readable ;-)