Skip to main content
davel001150
Inspiring
February 4, 2021
Question

How to find out whether a given ID is a Folder or a Document

  • February 4, 2021
  • 11 replies
  • 2 views

I have an ID.  It's currently an integer.

I want to know if there's a Document with that ID, or if there's a Folder with that ID.  Why?  Because if I guess and try to put it in the document() function, it will crash if it's a folder.  If I guess and try to put it in the folder() function, it will crash if it's a document.

I've tried plugins, but the plugins have a super fun tendency to throw lots of Java errors destroying our logs whenever we try to find out if this stupid thing is a Document or a Folder.

Is there a way to do this out of the box?  I want a rule that receives an integer and outputs the word "Document" or the word "Folder" or the word "Neither" and DOES NOT PINK BOX no matter what integer is.

11 replies

davel001150
Inspiring
February 4, 2021

For some reason it's impossible for me to use the property() function on a document or on a folder.

mikes0011
Brainy
February 4, 2021
use the property() function on a document

What makes you think this would work?  AFAIK that has nothing to do with what property() is intended to do.

The Expression Guru
davel001150
Inspiring
February 4, 2021

I want to get the "name" property of whatever kind of object it is.

See, the toDocument function works on an ID, and the toFolder function works on the same ID.  If it's REALLY a document, it will be a document with document properties like a "name" and an "extension", otherwise, they'd be null.  That could be a test, if only the durned thing worked.

mikes0011
Brainy
February 4, 2021

AFAIK you want Content Tools, and probably its function getContentObjectDetailsById(), which will return a string containing various properties (including type) of the ID you passed in.

I've whipped up a sample expression rule using this functionality that will return "Document" (plaintext) when the ID type is Document, "Folder" for a folder, and if no type is found, it will return the text "Invalid".  I forget off the top of my head whether any other object types will return (maybe KCs too?).  In any case it should work and hopefully won't clutter log files with too much junk, though that's usually something I worry about a lot later than getting functionality to actually work...

a!localVariables(
  local!details: getcontentobjectdetailsbyid(ri!objectId),
  local!extractedType: extract(local!details, "Type: ", ", Created"),
  
  index(local!extractedType, 1, "Invalid")
)

The Expression Guru
davel001150
Inspiring
February 4, 2021

That is EXACTLY what didn't work for the same reason isObjectExists() didn't work.  If you're in a script task, sure.  But if you're in a SAIL form, it doesn't work unless the person viewing the SAIL happens to be a system administrator.

If they're not a system administrator, prepare to see a bunch of Java language exceptions in the logs.

mikes0011
Brainy
February 4, 2021

That's annoying.  I assume the errors are a result of a basic user not having viewership permissions on the ID in question?

I'm not sure what a sufficient workaround might be (or whether there are any other plugins that circumvent this), and it's even moreso annoying that we don't have any ability to force functions on SAIL forms to run under the authority of an Admin account.

The Expression Guru