AnsweredAssumed Answered

execute a script only for a special filename

Question asked by stegbth on Dec 23, 2015
Latest reply on Jan 20, 2016 by niketapatel
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-files-scripts-08012008-1547
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-scripts-03232012-1135 -
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-scripts-03232012-1135


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

Outcomes