cancel
Showing results for 
Search instead for 
Did you mean: 

Howto Remove Entries from a Map in Rhino JavaScript

stevewickii
Champ in-the-making
Champ in-the-making
I am trying to remove a property from a node using the JavaScript API.  It should be possible.  I use the search.luceneSearch("query…") to get a list of ScriptNode objects.  Each ScriptNode has a "properties" member of type ScriptableQNameMap, and ScriptableQNameMap has a delete(String name) and remove(String name) method which both are defined to remove a property from the Map.

My problem is that I keep getting this error when I execute 'Delete Property.js': "EvaluatorException: missing name after . operator"

URL:  http:// localhost:9080/alfresco/command/script/execute?scriptPath=/Company%20Home/Data%20Dictionary/Scripts/Delete%20Property.js&property=fs:searchMeta

Delete Property.js
function main()
{
  if(!args.property)
  {
    return "Missing required request parameter: property";
  }

  var nodes = search.luceneSearch("TYPE:\"{www.fmcStars.nk.com/model/webcontent/1.0}downloadable\"");
  var propertyName = args.property;

  var str = "Deleted Property '"+ propertyName+" from the following Nodes:<hr>\r\n";

  for each (var node in nodes)
  {
    node.properties.delete(propertyName);
    node.save(); // This method uses NodeService.setProperties(), which should remove any properties from the Node that are not in the node.properties map.
    str += node.name+"<br>\r\n";
  }
  return str;
}

main();

Any help would be much appreciated.

Thanks!

Stephen
1 REPLY 1

mruflin
Champ in-the-making
Champ in-the-making
Hi Stephen,

delete is a reserved JavaScript keyword/language construct, not a function. Use follows syntax to delete an array element:


delete node.properties[propertyName];

This will remove the array element with key propertyName.