Well I would just use the scriptlistener code but if you don't want to for some reason you should make a reference to the activeLayer before add the new layer. Then use that reference as the moveAfter argument. The moveAfter method needs a layer object not a layer index. You need the index only because you are trying to supply that layer object by index.
Get the index of the layer before you create the new layer. When you create the new layer, it will be placed above the active layer, pushing the active layer down by one index number. So just add the appropiate index number when moving the layer.
Looks, Like Mike just beat me to the same answer, more or less.
That all makes sense, but why can't you create a self-referential layer?
var layerRef = app.activeDocument.artLayers.add() layerRef.name = "newlayername" layerRef.blendMode = BlendMode.NORMAL // Move the new layer after the current layer layerRef.moveAfter(layerRef)
Wherever you go, there you are. Using the layer you want to move as the argument really says 'move to the layer below yourself''. If you want it to move in relation to another layer you need to use that layer as the argument.
"You can't get there from here". Ok - i'll watch out for duplicate layernames in this instance.
It's more like here and there are the same place when you self reference the layer. It's always a good idea to watch out for dupe layernames but as you need a layer object you don't have to reference by name. The code I posted doesn't care about names. Nor would using the suggestion of getting activeLayer index before the add as csuebele suggested.
Yes, you want to add a line before all of you above code such as:
var origLayer = docRef.activeLayer
Then you can say: