Looks like error does not relate to any of those 3 lines of code. Also what is refDoc? Did you check what you get as a newGroup? What is layerIndexToMove? Could it be you are trying to move group into itself? After you create a group, indexes might change. Way too little info provided
Well… Error fires while trying to read id, but there’s nothing like it in your code, so it’s probably somewhere deeper. Error should say file and line where it occurs. Debug all your variables. What do you get for app.activeDocument.layers[layerIndexToMove]?
I think there is something wrong with this command or I am missing something.
The errors I get are these:
TypeError: Cannot read properties of undefined (reading ‘id’)
at _directRef (uxp://uxp-internal:1)
at Layer.moveInside (uxp://uxp-internal:1)
at Layer.move (uxp://uxp-internal:1)
at createMockup (VM16 app.js:294)
at async _internalExecuteAsModalWrapper (VM10 common.js:59)
at async _internalCallbackWrapper (VM10 common.js:40)
However, I tried a very simply scenario. Can you check if this is working for you?:
If you create group first and then layer, it works fine, but only if your active layer (when running script) was the very top one or you had no layers selected at all. But if active layer is other that the top-most, then you’re screwed
Just tried lots of different variations of selecting layer before move, selecting group before move, selecting none before move… Then in any case there’s this error. It seems like newLayer should be selected, but it still only works if script is ran when nothing or top-most selected.
First link is for older versions, but not sure now which ones, because it’s a mess I think it’s for earlier than Ps v23.0 and manifest v5. Probably would still work with manifest v4. As I said, noting versions in the docs is something Adobe doesn’t really bother about