Script Dialog List View: ID/Name Grouping Bugs

In the button script dialog, an error occurs when the view list obtains group objects based on group IDs

var gmap = {0: "G1", 1: "G2", 2: "G3"};
var smap = {0: 100, 1: 200, 2: 300};
var num = 0;
for(var k in gmap){
    var gid = listView.AddGroup(gmap[k], num++, "cd");
    DOpus.output(gid); // 0, 1, 2
}

listView.GetGroupById(0).name; // reports an error
listView.GetGroupById(1).name; // should result in G2, but the result is G3 (error)

In addition, it is hoped that the official team can extend and optimize the DialogListGroup object to allow modifying group names, so that the group names can be updated at any time in special business scenarios (such as dynamically updating group names after the list is loaded).

For example:
listView.GetGroupById(1).name = gmap[1] + "(" + smap[1] + ")";
or
listView.GetGroupById(1).value = gmap[1] + "(" + smap[1] + ")";

I think the real issue is just that groupid 0 is not properly "accepted" (or managed). Whatever group you try to add with AddGroup, if you assign it a 0 id (second parameter), it doesn't seem to be retrievable.
Since I have scripts using listviews with group ids value at 0, it is working internally, but something goes wrong with the GetGroupById method.

Note that the group id is not the value returned by the AddGroup as your code seems to imply (gid = listView.AddGroup). The group id is the value you provide as the second parameter.

1 Like

Thanks to @PassThePeas for the answer. I mistakenly took the return value of AddGroup() as the group ID, and moreover, the second parameter of AddGroup() cannot be 0.

Technically, it can be 0 but then something will go wrong with GetGroupById. There is something strange here. But the workaround is pretty easy: if you need to get the groups by Id, do not use 0 as an id :slight_smile:.
This really is an edge case IHMO: the only real usage would be to have a DialogListItem (coming from user selection for instance), and getting its group id and then wanting to get the name of that group or knowing if it's collapsed, since these really are the only two properties of that object (plus the id itself).

Well, thanks for clearing that up. Since I've never used the GetGroupById() function before, it was only when I needed to dynamically update group names this time that I discovered this issue. I've already modified the program: I start the list group IDs from 1, and then retrieve the group names in sequence using the group IDs, and the misalignment issue no longer occurs.
Of course, I hope the official team can add a function like set to the DialogListGroup object to facilitate updating group names.

As far as I can tell, our code doesn't treat group 0 specially. It's possible the OS itself does, although I didn't see anything in the documentation so far.

Is there a small, self-contained example we could use to test with, including the dialog resources and code to open the dialog etc.?

Sure, the script below demonstrates the problem.
You can toggle comments between lines 49 & 50 (EDIT: new line numbers after small cleanup in the script):

//var groupIdStart = 0;	// NOT WORKING - FAILS ON getGroupById(0)
	var groupIdStart = 1;	// WORKS

Here's the full code:

// (c) 2024 SALESSIO

// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information.



// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "TestGeneric";
	initData.version = "1.0";
	initData.copyright = "(c) 2024 SALESSIO";
//	initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "13.0";
  
}

// Called to add commands to Opus
function OnAddCommands(addCmdData)
{
	var cmd = addCmdData.AddCommand();
	cmd.name = "TestGeneric";
	cmd.method = "OnTestGeneric";
	cmd.desc = "";
	cmd.label = "TestGeneric";
	cmd.template = "";
	cmd.hide = false;
	cmd.icon = "script";
}

function OnTestGeneric(scriptCmdData)
{
    dout("Generic Test Command");

	var Dlg = DOpus.Dlg;
	Dlg.window = scriptCmdData.func.sourcetab;
	Dlg.template = "dlgListView";
	Dlg.detach = true;
	Dlg.Create();

	var listView = Dlg.Control("listview");
	listView.EnableGroupView(true);

	var gmap = {0: "G1", 1: "G2", 2: "G3"};
	var smap = {0: 100, 1: 200, 2: 300};
	//var groupIdStart = 0;	// NOT WORKING - FAILS ON getGroupById(0)
	var groupIdStart = 1;	// WORKS
	var num = groupIdStart;
	for(var k in gmap){
		var gid = listView.AddGroup(gmap[k], num++, "cd");
		DOpus.output("num + 1 (= groupId + 1) :" + num);
		DOpus.output(gid);
		// var uid = listView.AddItem(smap[k], num+5, num);
	}

	// dout("val = " + listView.GetGroupById(0));	// always undefined
	for (var i = groupIdStart; i < groupIdStart + 3; i++) {
		DOpus.Output(i + " > " + listView.GetGroupById(i).name);	// Fails for i = 0, even if groupId=0 has been added - listView.GetGroupById(0) is undefined
	}

	Dlg.Show();

	while (true) {
    	var msg = Dlg.GetMsg();
    	if (!msg.result) break;
    	DOpus.Output("Msg Event = " + msg.event + " / control = " + msg.Control + " / qualifiers = " + msg.qualifiers);
	}

	var ret= Dlg.result;
	DOpus.Output("Return code = " + ret + " / End of script");

}


function dout(msg) {
	DOpus.Output(msg);
}

==SCRIPT RESOURCES
<resources>
	<resource name="dlgListView" type="dialog">
		<dialog height="176" lang="francais" width="211">
			<control height="109" name="listview" type="listview" viewmode="details" width="175" x="16" y="20" />
		</dialog>
	</resource>
</resources>

EDIT:
With groupIds starting from one, output is:

 10/11/2025 18:11 TestGeneric:  Generic Test Command
 10/11/2025 18:11 TestGeneric:  num + 1 (= groupId + 1) :2
 10/11/2025 18:11 TestGeneric:  0
 10/11/2025 18:11 TestGeneric:  num + 1 (= groupId + 1) :3
 10/11/2025 18:11 TestGeneric:  1
 10/11/2025 18:11 TestGeneric:  num + 1 (= groupId + 1) :4
 10/11/2025 18:11 TestGeneric:  2
 10/11/2025 18:11 TestGeneric:  1 > G1
 10/11/2025 18:11 TestGeneric:  2 > G2
 10/11/2025 18:11 TestGeneric:  3 > G3
 10/11/2025 18:11 TestGeneric:  Msg Event = focus / control = listview / qualifiers = none
 10/11/2025 18:11 TestGeneric:  Return code = 0 / End of script

When starting from 0:

 10/11/2025 18:15 TestGeneric:  Generic Test Command
 10/11/2025 18:15 TestGeneric:  num + 1 (= groupId + 1) :1
 10/11/2025 18:15 TestGeneric:  0
 10/11/2025 18:15 TestGeneric:  num + 1 (= groupId + 1) :2
 10/11/2025 18:15 TestGeneric:  1
 10/11/2025 18:15 TestGeneric:  num + 1 (= groupId + 1) :3
 10/11/2025 18:15 TestGeneric:  2
 10/11/2025 18:15 TestGeneric:  Erreur Ă  la ligne 61, position 3
 10/11/2025 18:15 TestGeneric:  Impossible d’obtenir la propriété  « name » d’une référence null ou non définie (0x800a138f)

name property does not exists on a null or undefined object.
That can also be seen when uncommenting line 59: GetGroupById(0) returns undefined, even when first group id is 0.

1 Like

Many thanks!

That was a bug on our side. It has been fixed for the next beta.

1 Like

I can report that a group with id=0 is still not visible in 13.20.2

listview.AddGroup("groupname", 0, "c");

The docs lack information about what the AddGroup() return value stands for (i guess its the index of the group, not its id).

Do you have a minimal example script that shows the problem?

(The one above doesn't create any visible items, in any group.)

Listview group 0 .dcf (6.8 KB)

That's a bug in your script code:

	if(!groupId)
    	addedIndex = listView.AddItem(name, id);
	else
		addedIndex = listView.AddItem(name, id, groupId);

Didnt think about 0 being evaluated as false :melting_face: i