cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get custom property value through Javascript

stallapragada
Champ in-the-making
Champ in-the-making
Hi

I am having a javascript to extract the custom properties of a document when it is being added to Alfresco. I have a requirement to auto folder this document in a folder that is dynamically created based on the custom property of this document. So, I defined a rule and am having a javascript executed wheneever a document belonging to this type is being added to Alfresco. I have the following code snippet in my javascript that is returning null due to which the folder creation process is failing.

var empId = document.properties["dc:eId"];

Whereas, when I try to get the name of the document, I am able to get it using the following code.

var docName = document.properties["name"];

What I am failing to understand is that I am able to set the custom property from "Add Content" wizard. I can see the value of the same after the document is added. Also, I am able to search the document based on the custom property. The only thing that is failing is the retrieval of this property value by the javascript.

Any clues?

-Thanks
Srikant
Principal Consultant
IntrospeQt Software India Pvt Ltd
http://www.introspeQt.com
14 REPLIES 14

kevinr
Star Contributor
Star Contributor
If you expand the node object in the debugger and look at the "properties" collection - does it show the values in that?

stallapragada
Champ in-the-making
Champ in-the-making
Kevin

I can see the custom property names but the values for them is null in the debugger. However I can see values for certain properties like name and title.

-Thanks
Srikant
Principal Consultant
IntrospeQt Software India Pvt Ltd
http://www.introspeQt.com

derek
Star Contributor
Star Contributor
Hi,

The code that handles the upload is AddContentDialog.  This goes through two phases (see BaseDialogBean😞 finishImpl; doPostCommitProcessing.  The post commit processing is actually where the user is given the opportunity to enter further metadata, but the document has already been uploaded into Alfresco i.e. the document upload transaction was committed.  Your initial action is probably firing after the first commit and hence not seeing the custom metadata, even though it might appear, to the user, that the document upload is not complete.

Your script action will have to handle both initial upload (with or without full metadata) and updates of the metadata.  To do this, you will have to trigger your actions off document updates as well.

Regards

stallapragada
Champ in-the-making
Champ in-the-making
Can you detail me or point to a location on how to do this?

-Thanks
Srikant
Principal Consultant
IntrospeQt Software India Pvt Ltd
http://www.introspeQt.com

nikes
Champ on-the-rise
Champ on-the-rise
Hi stallapragada,

I wrote following JavaScript for similar requirement (Loan related document upload)

var prop = document.properties["custom:applicationNo"];
var existsSpace = space.childByNamePath(prop);
var dest;

if(existsSpace == null)
{
   dest = space.createFolder(prop);
   document.move(dest);
}
else
{
   document.move(existsSpace);
}

Created rule on update event instead of Inbound event.

Thanks,
Nikesh