JavaScript API Error on rule/action
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2013 03:49 PM
I'm try to write a script for create a new subfolder when email is send to an alfresco folder (associted to an alias) via SMTP.
I need to create this subfolder under the folder that is performing the rule;therefore, the new folder should be named as the Subject field of the email arrived.
The script is associated to the folder via rule, and i try to execute it in backgroud and not. The rule i applied only to document that have the "emailed" Aspect.
I cannot use the debugger, because an issue of alfresco 4.2d edition. But i had try debugging code omitting some line and the error is in the -document.properties["cm:subjectline"] - function. If i set it with static string the folder is created.
This is the code/flow:
/* The mail new mail arrive to folder with alias rnc@cms.pasello.com */
var id = companyhome.id;
var name = companyhome.name;
var type = companyhome.type;
var noderef = companyhome.nodeRef;
var childList = companyhome.children;
var properties = companyhome.properties;
var assocs = companyhome.assocs;
/*I change doccument mimetype for correct preview and save it */
document.mimetype="text/html";
document.save();
/*Add a new folder naming it with the same name as email subject */
var newRNCFolder = space.childByNamePath(document.properties["cm:subjectline"]);
if (newRNCFolder == null && space.hasPermission("CreateChildren"))
{
// create the folder for the first time
newRNCFolder = space.createFolder(document.properties["cm:subjectline"]);
}
space.save();
I need to create this subfolder under the folder that is performing the rule;therefore, the new folder should be named as the Subject field of the email arrived.
The script is associated to the folder via rule, and i try to execute it in backgroud and not. The rule i applied only to document that have the "emailed" Aspect.
I cannot use the debugger, because an issue of alfresco 4.2d edition. But i had try debugging code omitting some line and the error is in the -document.properties["cm:subjectline"] - function. If i set it with static string the folder is created.
This is the code/flow:
/* The mail new mail arrive to folder with alias rnc@cms.pasello.com */
var id = companyhome.id;
var name = companyhome.name;
var type = companyhome.type;
var noderef = companyhome.nodeRef;
var childList = companyhome.children;
var properties = companyhome.properties;
var assocs = companyhome.assocs;
/*I change doccument mimetype for correct preview and save it */
document.mimetype="text/html";
document.save();
/*Add a new folder naming it with the same name as email subject */
var newRNCFolder = space.childByNamePath(document.properties["cm:subjectline"]);
if (newRNCFolder == null && space.hasPermission("CreateChildren"))
{
// create the folder for the first time
newRNCFolder = space.createFolder(document.properties["cm:subjectline"]);
}
space.save();
Labels:
- Labels:
-
Archive
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2013 06:44 AM
Hello,
the property cm:subjectline may simply not be set which will result in errors when you attempt to create a folder without providing a name (or even an invalid name, as the value of cm:subjectline can be incompatible with the required file / folder name). I'd suggest adding the necessary checks to your script, i.e. verify that cm:subjectline actually has a value and then attempt to lookup / create a folder based on it - additionaly, you must make sure to sanitize cm:subjectline to comply with cm:name constraints about allowed format.
Regards
Axel
the property cm:subjectline may simply not be set which will result in errors when you attempt to create a folder without providing a name (or even an invalid name, as the value of cm:subjectline can be incompatible with the required file / folder name). I'd suggest adding the necessary checks to your script, i.e. verify that cm:subjectline actually has a value and then attempt to lookup / create a folder based on it - additionaly, you must make sure to sanitize cm:subjectline to comply with cm:name constraints about allowed format.
Regards
Axel
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2013 03:23 AM
