execute a script only for a special filename

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2015 04:53 AM
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:
This are some tests i made as described here
https://forums.alfresco.com/forum/developer-discussions/other-apis/string-operations-alfresco-script...
catalina.out
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "java" is not defined
catalina.out
no function resize
no error, no resize
best regards
Thomas
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
Labels:
- Labels:
-
Archive
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2016 01:33 AM
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!
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!
