cancel
Showing results for 
Search instead for 
Did you mean: 

script to execute on content rule - add metadata

gnyce
Champ in-the-making
Champ in-the-making
I am attempting to write a (java)script that will execute on a content rule - specifically, to add some required metadata to a record within a Records Mgmt site.  I think I've managed to find the model definitions… in recordsModel.xml (and maybe recordsCustomModel.xml?)….

rmaSmiley SurprisedriginatingOrganzation
rmaSmiley TongueublicationDate
rmaSmiley Surprisedriginator

And so tried the code below, cribbed a bit from another example.

// doc.properties["my:prop1"] = "new constant value";
// doc.properties["my:prop2"] = "new other constant value"';
doc.properties["rma:originator"] = "John Q. Author";
doc.properties["rma:originationOrganization"] = "SomeCO Limited Inc.";
doc.properties["rma:publicationDate"] = "Fri Feb 04 01:00:00 EST 2011";
/* more stuff */
doc.save();  /* to save the properties just set *

However, when I try to upload a record, and this rule files, it fails, and the catalina.out logs this: 
"22:28:40,403 User:gnyce ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 01040963 Failed to execute script 'workspace://SpacesStore/6376f7ac-4516-4809-8db3-94b08bb32cab':
01040962 ReferenceError: "doc" is not defined. (workspace://SpacesStore/6376f7ac-4516-4809-8db3-94b08bb32cab#3)
org.alfresco.scripts.ScriptException: 01040963 Failed to execute script 'workspace://SpacesStore/6376f7ac-4516-4809-8d
b3-94b08bb32cab': 01040962 ReferenceError: "doc" is not defined. (workspace://SpacesStore/6376f7ac-4516-4809-8db3-94b0
8bb32cab#3)        at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:244)
        at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:195)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
<SNIP>
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "doc" is not defined. (workspace://SpacesStore/6376f7ac-4516-4809-8db3-94b08bb32cab#3)"

Which seems to indicate that I need to, in the script, somehow refer to or provide a handle to the uploaded record.

Questions:

1. how do I, in javascript, specify the document being uploaded?  Is that setting a javascript variable via the document spacestore ID?  How do I get that (upon the doc being uploaded?

2. how do I find the nomenclature of RM custom fields added?  I'll need a handle to be able to set metadata on them.

I'm not a developer at all, so am stumbling around quite a bit - feels like I've made a little progress, but hoping for some pointer(s).

thank you
3 REPLIES 3

gnyce
Champ in-the-making
Champ in-the-making
OK, got originator and originatingOrganization working.  Currently stuck on setting the date - what format it wants, etc.  Once I get that figured out, will work on the custom metadata field.

Caused by: org.alfresco.service.cmr.repository.datatype.TypeConversionException: The property value is not compatible
with the type defined for the property:
   property: Name: {http://www.alfresco.org/model/recordsmanagement/1.0}publicationDateTitle: Publication Date
Description: null
Default Value: null
DataType Name: {http://www.alfresco.org/model/dictionary/1.0}date
ContainerClass Name: {http://www.alfresco.org/model/recordsmanagement/1.0}record
isMultiValued: false
isMandatory: true
isMandatoryEnforced: falseisProtected: false
isIndexed: true
isStoredInIndex: false
isIndexedAtomically: true
indexTokenisationMode: TRUE

   value: 2011020400:00:00
   value type: class java.lang.String

gnyce
Champ in-the-making
Champ in-the-making
Punted on the date - just set it to be the same as created value.  Now to figure out how to address/refer-to the custom metadata field (already setup within the RM Console).
//set variable to be the created value, then set values
var PubDate = document.properties["cm:created"];
document.properties["rma:originator"] = "John Q. Originator";
document.properties["rma:originatingOrganization"] = "SOMECO Company Ltd Inc";
document.properties["rma:publicationDate"] = PubDate;
document.save();

gnyce
Champ in-the-making
Champ in-the-making
Got it - looking at the RecordsCustomModel.xml, seemed like I could refer to the custom field by using "rmc:NameOfMyCustomField", and it worked.
document.properties["rmc:MyCustomFieldNameHere"] = "Fill in field with this metadata";