[HELP] Why in this script column group is not working?

Hi I made some test with custom columns and I don't understand why in this test grouping is not working, not even auto group, Can somebody help me out?
This is the code.

// The OnInit function is called by Directory Opus to initialize the script add-in

var months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]
function OnInit(initData) {

    // Provide basic information about the script by initializing the properties of the ScriptInitData object
    initData.name = "ByDate";
    initData.default_enable = true;
    //Set to true if you want to use dates for folders instead of the newest inside.
    initData.config.UseFolderDate = false;
    //Set maximum items to recurse inside a folder
    initData.config.maxItemsPerFolder = 10;
    // Create a new ScriptColumn object and initialize it to add the column to Opus
    var cmd = initData.AddColumn();
    cmd.name = "ByDate";
    cmd.method = "ByDate";
    cmd.label = "Creación | Modif.";
    cmd.multicol = false;
    cmd.autogroup = true;       // we provide our own grouping information
	cmd.autorefresh = true;      // auto-refresh column when file changes
    cmd.type = "datetime";
    // cmd.grouporder = "Del Futuro!;Hoy;Esta semana;Este mes;Este año;El año pasado;Hace mucho tiempo";
}

function ByDate(scriptColData) {
    item_time = scriptColData.item.create.Compare(scriptColData.item.modify) > 0 ? scriptColData.item.create : scriptColData.item.modify;
    //if item is dir and UseFolderDate is false we pick the date from inside the folder
    if (scriptColData.item.is_dir && !Script.config.UseFolderDate) 
    {
        var i = 1;
        FolderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, false);
        while (!FolderEnum.complete && i < Script.config.maxItemsPerFolder)
        {
            FolderItem = FolderEnum.next;
            ntime = FolderItem.create.Compare(FolderItem.modify) > 0 ? FolderItem.create : FolderItem.modify;
            if (item_time.Compare(ntime) < 0)
                item_time = ntime;
            i++;
        }
    }
    scriptColData.value = item_time.Format();
    // var today = DOpus.NewDate();
    // if (today.Compare(item_time) == -1) 
    // {
    //     DOpus.Output("Del Futuro!");
    //     scriptColData.group = "Del Futuro!";
    //     scriptColData.sort = 1;
    // }
    // else if (today.Compare(item_time, "d"))
    // {
    //     scriptColData.group = "Hoy";
    //     scriptColData.sort = 2;
    // }
    // // Si son de la misma semana
    // // else if (today.year == item_time.year) 
    // // {
    // // 	var group = "Este año";
    // // 	var sort = 5;
    // // 	//Si son del mismo mes
    // // 	if (today.month == item_time.month) 
    // // 	{
    // // 		sort = 4;
    // // 		group = "Este mes";
    // // 		//Si son de la misma semana
    // //         if (today.day - today.wday == item_time.day - item_time.wday)
    // //         {
    // //          sort = 3;
    // //          group = "Esta semana";
	   // //  		//Si son del mismo dia
    // //         }
    // //    }
    // //    DOpus.Output(group);

    // //    scriptColData.group = group;
    // //    scriptColData.sort = sort;
    // // }
    // //Si es del año pasado
    // else if (today.year - 1 == item_time.year) {
    //     DOpus.Output("El año pasado");

    //     scriptColData.group = "El año pasado";
    //     scriptColData.sort = 6;
    // }
    // // Es de hace mucho tiempo
    // else {
    //     DOpus.Output("Hace tiempo");

    //     scriptColData.group = "Hace tiempo";
    //     scriptColData.sort = 7;
    // }
}

PS: The column that I want to create acts(group, sorting) exactly as date related columns already, but instead use the newest date between creation/modification. Can somebody also help me out with a better code. The one above is too clumsy in my opinion.

If you want automatic grouping by date, you need to:

  • Set the column type to date.
  • Set the column values to dates (you're setting the values to strings at the moment; you don't want the Format call, just use the date as-is).
  • Opus 11.5.2 or above is also required.

My newest file column, in the scripts area, can be used as a working example.

Ok, thanks Leo, but if you just see on the code I posted above, (just uncomment some lines) I make use of my own grouping method, althought still all the items goes to Unespecified. Can you please check it out? Thanks

It's hard to know which lines you mean when you say "just uncomment some lines". For example, cmd.autogroup = true; will stop manual grouping from working and you don't have that line commented in the first place.

It's better to post the actual script you're trying, with the appropriate lines already uncommented, rather than us having to guess what you've tried and what you haven't.

Ok, here they go:

// The OnInit function is called by Directory Opus to initialize the script add-in

var months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"]
function OnInit(initData) {

    // Provide basic information about the script by initializing the properties of the ScriptInitData object
    initData.name = "ByDate";
    initData.default_enable = true;
    //Set to true if you want to use dates for folders instead of the newest inside.
    initData.config.UseFolderDate = false;
    //Set maximum items to recurse inside a folder
    initData.config.maxItemsPerFolder = 10;
    // Create a new ScriptColumn object and initialize it to add the column to Opus
    var cmd = initData.AddColumn();
    cmd.name = "ByDate";
    cmd.method = "ByDate";
    cmd.label = "Creación | Modif.";
    cmd.multicol = false;
    cmd.justify = "right";
    cmd.autogroup = false;       // we provide our own grouping information
	cmd.autorefresh = true;      // auto-refresh column when file changes
    cmd.grouporder = "Del Futuro!;Hoy;Esta semana;Este mes;Este año;El año pasado;Hace mucho tiempo";
}

function ByDate(scriptColData) {
    item_time = scriptColData.item.create.Compare(scriptColData.item.modify) > 0 ? scriptColData.item.create : scriptColData.item.modify;
    //if item is dir and UseFolderDate is false we pick the date from inside the folder
    if (scriptColData.item.is_dir && !Script.config.UseFolderDate) 
    {
        var i = 1;
        FolderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, false);
        while (!FolderEnum.complete && i < Script.config.maxItemsPerFolder)
        {
            FolderItem = FolderEnum.next;
            ntime = FolderItem.create.Compare(FolderItem.modify) > 0 ? FolderItem.create : FolderItem.modify;
            if (item_time.Compare(ntime) < 0)
                item_time = ntime;
            i++;
        }
    }
    scriptColData.value = item_time;
    var today = DOpus.NewDate();
    if (today.Compare(item_time) == -1) 
    {
        //DOpus.Output("Del Futuro!");
        scriptColData.group = "Del Futuro!";
        scriptColData.sort = 1;
    }
    else if (today.Compare(item_time, "d"))
    {
        scriptColData.group = "Hoy";
        scriptColData.sort = 2;
    }
    else if (today.year == item_time.year) 
    {
    	var group = "Este año";
    	var sort = 5;
    	//Si son del mismo mes
    	if (today.month == item_time.month) 
    	{
    		sort = 4;
    		group = "Este mes";
    		//Si son de la misma semana
            if (today.day - today.wday == item_time.day - item_time.wday)
            {
             sort = 3;
             group = "Esta semana";
	    		//Si son del mismo dia
            }
       }
       scriptColData.group = group;
       scriptColData.sort = sort;
    }
    else if (today.year - 1 == item_time.year) {
        scriptColData.group = "El año pasado";
        scriptColData.sort = 6;
    }
    // Es de hace mucho tiempo
    else {
        scriptColData.group = "Hace tiempo";
        scriptColData.sort = 7;
    }
}

So? I can't make it work.

To fix it:

  1. in OnInit, add this line when you add the column:
cmd.type = "date"; // or "datetime"
  1. In ByDate, fix your comparison for "Hoy":
else if (today.Compare(item_time, "d") == 0)