Replacing findfoldersbyname() with findcontentbyattribute() Content Tools Plugin

I am trying to replace findfoldersbyname() with findcontentbyattribute(), but can only get findcontentbyattribute() to return a List of Content, it returns something like [Content:56629].

 Is there any way to return the folder itself instead of [Content:56629]? 

findfoldersbyname() returns a folder object and I would like findcontentbyattribute() to do the same or somehow use what it returns ([Content:56629]) to return the folder itself.

  Discussion posts and replies are publicly visible

Parents
  • At the end of the day, a folder is just an ID, regardless of what data type it's been wrapped in.  What happens when you wrap the output in toFolder()?

  • Hi Mike, 

    When I do toFolder() with its input being what is returned from findcontentbyattribute() i.e. a list of Content ([Content:56629]), nothing is returned.

    Then I tried to index() the list of Content to try and retrieve 56629. Index([Content:56629], "Content"), and I received an error: Invalid index: Cannot index property 'Content' of type Text into type List of Content.

    Then I used a foreach() to index the list of content i.e. foreach([Content:56629], fv!item). This successfully singled out 56629 as an integer. Then, doing tofolder() retrieved a the correct folder object.

    I was wondering why index() does not work on the list of content? Or is there any other (more efficient way than foreach) to retrieve the 56629 from the list of Content?

Reply
  • Hi Mike, 

    When I do toFolder() with its input being what is returned from findcontentbyattribute() i.e. a list of Content ([Content:56629]), nothing is returned.

    Then I tried to index() the list of Content to try and retrieve 56629. Index([Content:56629], "Content"), and I received an error: Invalid index: Cannot index property 'Content' of type Text into type List of Content.

    Then I used a foreach() to index the list of content i.e. foreach([Content:56629], fv!item). This successfully singled out 56629 as an integer. Then, doing tofolder() retrieved a the correct folder object.

    I was wondering why index() does not work on the list of content? Or is there any other (more efficient way than foreach) to retrieve the 56629 from the list of Content?

Children
  • 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))
    )