Rule (and its script) not working as expected
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2013 04:52 PM
I have created a folder and a rule for this folder which will, upon file creation:
- change the node to a new content type (which is a child of cm:content); and
- execute a little script which is meant to populate two of its properties:
(Basically I'm just incrementing the value of contractID so the user doesn't have to. It's not a terribly meaningful value to a human.)
The node is changed to the content type as expected. The query works and returns what I expect it to return. The last two lines, however, appear to do nothing. They definitely refer to properties of this model.
Can anyone think of a reason why this isn't working? Does Alfresco just need more time between setting the content type and accessing its properties?
- change the node to a new content type (which is a child of cm:content); and
- execute a little script which is meant to populate two of its properties:
var results=search.luceneSearch("+PATH:\"/app:company_home/st:sites/cm:contract-management/cm:documentLibrary/cm:ActiveContracts//*\"+TYPE:\"{duca.contracts.model}contract\"");var maxContractNumber=0;for (var i=0;i<results.length;i++){ if (results.properties["contract:contractID"]>maxContractNumber) { maxContractNumber=results.properties["contract:contractID"]; }}document.properties["contract:contractID"]=maxContractNumber+1;document.properties["contract:isActive"]=true;
(Basically I'm just incrementing the value of contractID so the user doesn't have to. It's not a terribly meaningful value to a human.)
The node is changed to the content type as expected. The query works and returns what I expect it to return. The last two lines, however, appear to do nothing. They definitely refer to properties of this model.
Can anyone think of a reason why this isn't working? Does Alfresco just need more time between setting the content type and accessing its properties?
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2013 01:19 AM
Add this line in the end
document.save();
document.save();
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2013 09:22 AM
Yeah, that was it, thanks.
Another minor problem: when I update that contractID property, I'm giving it an integer. I even did this:
to make sure I was passing in an integer. But the value I see in Alfresco is "3.0" or whatever. Is there any way to make sure Alfresco takes an integer value, rather than a float/double/whatever?
Another minor problem: when I update that contractID property, I'm giving it an integer. I even did this:
document.properties["contract:contractID"]=Math.round(maxContractNumber+1);
to make sure I was passing in an integer. But the value I see in Alfresco is "3.0" or whatever. Is there any way to make sure Alfresco takes an integer value, rather than a float/double/whatever?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2013 04:55 PM
How did you define this property in your data model? That is probably your issue.
Or try passing the parseInt(maxContractNumber + 1) to the property.
Also, as a suggestion, you can make a property, or even a simple file or something on the data dictionary. Keep the max contract Id there. That way your script will run fast even when there are thousands of contracts already (as you're now looping them all).
So basically you have a file and it's property (could be anything, even in a page title.). Then in this script just go, fetch that number, increment it by 1, and assign it to the next contract. As an added value, you can even manually change the max contract number from there, or 'rewind' the counter if needed.
Or try passing the parseInt(maxContractNumber + 1) to the property.
Also, as a suggestion, you can make a property, or even a simple file or something on the data dictionary. Keep the max contract Id there. That way your script will run fast even when there are thousands of contracts already (as you're now looping them all).
So basically you have a file and it's property (could be anything, even in a page title.). Then in this script just go, fetch that number, increment it by 1, and assign it to the next contract. As an added value, you can even manually change the max contract number from there, or 'rewind' the counter if needed.
