I was wondering why index() does not work on the list of content?
Index() is for returning the position in an array. It can also do what property() does and return a dot property. But the result given by the contentByAttribute() plug-in is, as far as I know, basically just an integer - meaning the data doesn't actually have a property called "Content", it's literally just an integer wrapped in a data type ("Content") where the default output is a string that says "[Content:56629]". But this is not a dictionary/CDT, it's just integer data.
In any case, when you wrap such output in tointeger(), anything inside the string that's an integer gets pulled out and returned by the function.
I do notice "tofolder()" doesn't play nicely with the direct output of the function. But when you wrap the output in tointeger() first it seems ok.
a!localVariables(
local!directOutput: findcontentbyattribute(
searchAllContent: false(),
contentType: "folder",
attributeName: "name",
searchCriteria: "Additional Documents",
rootFolder: 12345
),
/* tofolder() and tointeger() both play nice with array inputs, so no real need to do a!forEach() here */
tofolder(tointeger(local!directOutput))
)