1

I'm doing something like this:

document.properties["my:customProperty"] = getSomehowTheProperty(document);

my:customProperty is a string, which has some allowed values in the content model.

How can I get the allowed values from the content model, so that I don't have to store them in a JavaScript array inside the script?

Or how else can I check, that the function getSomehowTheProperty returned an allowed value?

I tried to wrap it with try-catch:

    try {
      document.properties["my:customProperty"] = getSomehowTheProperty(document);
      document.save();
    } catch (e) {
      document.properties["my:customProperty"] = "Default Value";
      document.save();
    }

But it looks like integrity is checked and th error is thrown at the end of executing the script, not inside the try block.

Googling "alfresco js allowed values of node properties" and similar queries gives me nothing.

2
  • Where is the JS running? Alfresco repo? Share tier? Web Browser?
    – Gagravarr
    Commented Jun 12, 2013 at 11:35
  • The script is a file in the repo under /Data Dictionary/Scripts/. It is executed as a content rule action in some space, when new document is uploaded to the space. Sorry for not being clear enough at first and hope it's better now.
    – slaweet
    Commented Jun 12, 2013 at 14:46

1 Answer 1

2

In order to get that sort of information, you'll have to use the DictionaryService to get the PropertyDefinition

Off the top of my head, you'll want to do something like:

QName customPropertyQ = QName.createQName("my:customProperty", namespaceService);
PropertyDefinition customPropertyT = dictionaryService.getProperty(customPropertyQ);
List allowedValues = customPropertyT.getConstraints();

That'd be in Java, see this blog post for details on how to work with the DictionaryService from JavaScript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.