GetItem doesn't create filegroup property

The fsu.GetItem() method seems to fail to create the item.filegroup property. Or is my script wrong?

Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>GetItem Demo</label>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    var fsu = DOpus.FSUtil();</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    var item = tab.selected_files(0);</instruction>
		<instruction />
		<instruction>    DOpus.Output(&apos;item:              &apos; + item);</instruction>
		<instruction>    DOpus.Output(&apos;item.filegroup:    &apos; + item.filegroup);</instruction>
		<instruction />
		<instruction>    var newItem = fsu.GetItem(fsu.Resolve(item));</instruction>
		<instruction />
		<instruction>    DOpus.Output(&apos;newItem:           &apos; + newItem);</instruction>
		<instruction>    DOpus.Output(&apos;newItem.filegroup: &apos; + newItem.filegroup);</instruction>

The item.filegroup property only makes sense for an item that came from a folder tab, since it tells you which (if any) group the file is in if the folder tab is grouped by a column.

If you're after the file type group(s) rather than the sort/column group, the groups or groupsobject properties should give you that.

Yes, in this case the property is meaningless, but accessing it shouldn't result in a script error IMO.

Wouldn't an empty string or undefined be more appropriate?

I think either that or what it does now would both be valid. What it does now is intentional in the code, FWIW.

It's a logic error to query the property in a situation where it cannot have any meaning, so the property failing (not just returning an empty result) may alert people to the fact they're using it incorrectly. But I imagine there are also lots of cases where we don't do that, too.

Is it causing a problem?

No, nothing major. Let's leave like this, if it's by design. I guess it'll be several years of scripting until I run into this situation again :slight_smile:

1 Like