cancel
Showing results for 
Search instead for 
Did you mean: 

execute a script only for a special filename

stegbth
Champ in-the-making
Champ in-the-making
Hi,

i am trying to mogrify uploaded pictures to a fixed size.
so i found here an appropriate Javascript here
https://forums.alfresco.com/forum/developer-discussions/alfresco-explorer-development/overwrite-file...
I created a rule, which execute the script when a jpeg get uploaded, which
is not optimal, cause this runs in an endless loop.

Now i tried to check the documentname in the script if it contains or
starts with resized_.. but no solution as described here - https://forums.alfresco.com/forum/developer-discussions/other-apis/string-operations-alfresco-script... -
worked.

Could some hint me to the correct syntax for the if clause?

The currect Script looks like this:


var strOrigName = document.properties.name;
var jstrOrigName = new java.lang.String(document.properties.name);

if (!jstrOrigName.contains("resized_")) {
var tmpName = "resized_" + document.properties.name;
document.properties.name = tmpName;
var rImage=document.transformImage("image/jpeg","-normalize -resize
1024x768", document.parent);
if (rImage){
  document.properties.name = strOrigName;
  document.save();
  document.remove();
}
}


This are some tests i made as described here
https://forums.alfresco.com/forum/developer-discussions/other-apis/string-operations-alfresco-script...


var jstrOrigName = new java.lang.String(document.properties.name);
if (!jstrOrigName.contains("resized_")) {

catalina.out
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "java" is not defined


var jSstrOrigName = new String(document.properties.name);
if (!jSstrOrigName.contains("resized_")){

catalina.out
no function resize


if (strOrigName.indexOf("resized_") != -1){

no error, no resize

best regards
Thomas
1 REPLY 1

niketapatel
Star Contributor
Star Contributor
You can use alfresco OOB condition while applying rule to execute js.

Select conditions –> Name contains value – add your file name text pattern.

So you will not need to make this name check in your js.

hope this helps!