cancel
Showing results for 
Search instead for 
Did you mean: 

Custom behavior

ltardioli
Champ in-the-making
Champ in-the-making
Hello ppl!

I'm trying to write a custom behavior to my custom model.

I created the beans, javascript e etc. but when javascript is called it throws this error: TypeError: Cannot read property "cm:name" from undefined.


var scriptFailed = false;

// Have a look at the behaviour object that should have been passed
if (behaviour == null) {
    logger.log("The behaviour object has not been set.");
    scriptFailed = true;
}

// Check the name of the behaviour
if (behaviour.name == null && behaviour.name != "onCreateNode") {
    logger.log("The behaviour name has not been set correctly.");
    scriptFailed = true;
} else {
    logger.log("Behaviour name: " + behaviour.name);
}

// Check the arguments
if (behaviour.args == null) {
    logger.log("The args have not been set.");
    scriptFailed = true;
} else {
    if (behaviour.args.length == 1) {
        var childAssoc = behaviour.args[0];
        logger.log("Calling compute average");
        //computeAverage(childAssoc);
      
      var clienteName = childAssoc.properties["cm:name"];
                childAssoc.properties["cm:content"] = clienteName;
          
      childAssoc.save();
      
    } else {
        logger.log("The number of arguments is incorrect.");
        scriptFailed = true;
    }
}       

Seems that model is null but how can I get my model's properties?


2 REPLIES 2

mitpatoliya
Star Collaborator
Star Collaborator
I think there is problem in your script
childAssoc is not directly pointing to script node so
childAssoc.properties it self is not defined.
You need to get scriptnode from that and then you can get the name from that node.

ltardioli
Champ in-the-making
Champ in-the-making
And how can I do that?

I tryed logger.log(childAssoc.name) and I got: {http://www.alfresco.org/model/content/1.0}test, so I think that childAssoc is not undefined but when I try to get the properties Alfresco says that I cant read property from undefined.

Thanks for replay!