Problems working with events, nodelib/contentlib in main.js

Enonic version: 6.13.1
OS: Windows 10

// main.js
var nodeLib = require('/lib/xp/node');
var event = require('/lib/xp/event');

  type: 'node.rename',
  callback: function(event) {
    var repo = nodeLib.connect({
      repoId: 'cms-repo',
      branch: 'draft' 
    var eventNode =;
    var node = repo.get(;
    if (!node)'Missing node') // <-- This kicks in every time
    else {
       /* do things with node */

The callback for the event listener is called in a different context. It might be that when calling repo.get() you don’t have permissions to read the node.

Try passing the user in the call to nodelib.connect(...).


Yep, passing principals to the connection fixed it :slight_smile:

This topic was automatically closed after 24 hours. New replies are no longer allowed.