AnsweredAssumed Answered

script to execute on content rule - add metadata

Question asked by gnyce on Feb 5, 2011
Latest reply on Feb 6, 2011 by gnyce
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?)….

rma:originatingOrganzation
rma:publicationDate
rma:originator

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

Outcomes