Draško
Draško

Reputation: 2221

How to set/change creator of document in alfresco in webscript

How can I change 'creator' property in webscript in Alfresco of uploaded document?

I am using Alfresco 4.2, btw.

Best, D

Upvotes: 2

Views: 4990

Answers (3)

Yon Santos
Yon Santos

Reputation: 131

If I'm not wrong cm:creator, cm:modifier, cm:created, cm:modified, etc...are auditable properties in Alfresco it means, can't be updated manually because are managed by Alfresco.

I have developed a java backed webscript and I have added this code (to update the creator and modifier properties) that is working properly:

// Disable auditable aspect to allow change properties of cm:auditable aspect
policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

// Update properties of cm:auditable aspect
nodeService.setProperty(nodeRef, ContentModel.PROP_CREATOR, "xxxxxx");
nodeService.setProperty(nodeRef, ContentModel.PROP_MODIFIER, "xxxxxx");

// Enable auditable aspect
policyBehaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

Don't forget to add in your context.xml file where you declare your beans:

<bean id="xxxxxxxx" 
      class="your class package"
  parent="webscript">
  <property name="nodeService" ref="NodeService" />
  ........
      <property name="policyBehaviourFilter" ref="policyBehaviourFilter" />     
</bean> 

Good luck

Upvotes: 6

Tahir Malik
Tahir Malik

Reputation: 6643

You can take a look at this forum post.

Like stated, after the field is set it can't be changed any more. You could or change the contentModel.xml to set the cm:creator field to default (which is read and write).

Or you could copy the document on the moment and set the FullyAuthenticatedUser for a short time and revert it afterwards. You will need to write some Java Code for it (e.g. in a Java Action).

Upvotes: 1

shkwav
shkwav

Reputation: 126

The "cm:creator" is a controlled audited property that cannot be changed directly. Much like "cm:modifier" which is updated by the system when a user authority modifies the content/properties (content is just a special property really) of the document node.

You can change the owner of a document via the Repository APIs. This is a permissions change though and will still not change the cm:creator property (and it shouldn't).

Upvotes: 4

Related Questions