GROUPBY=modifieddate - Break 'A long time ago' in smaller junks

Here is a script that introduces a column Age and lets you define groups how you want them. Just whistle if you need help adapting them to your liking.

function OnInit(initData) {
  initData.name = 'Age';
  initData.version = '2021-12-09';
  initData.copyright = '';
  initData.url = 'https://resource.dopus.com/t/groupby-modifieddate-break-a-long-time-ago-in-smaller-junks/40038';
  initData.desc = '';
  initData.default_enable = true;
  initData.min_version = '12.0';
}

function OnAddColumns(addColData) {
  var col = addColData.AddColumn();
  col.name = 'Age';
  col.label = 'Age';
  col.header = 'Age';
  col.justify = 'right';
  col.autogroup = false;
  col.grouporder = 'one month;half a year;one year;3 years;5 years;7 years;10 years;15 years;20 years;over 20 years';
  col.method = 'OnColumn';
}

function OnColumn(scriptColData) {
  var age = (DOpus.Create().Date() - scriptColData.item.modify) / (1000 * 60 * 60 * 24); // age in days
  var proseAge;

  if (age < 30) {
    proseAge = 'one month';
  } else if (age < 180) {
    proseAge = 'half a year';
  } else if (age < 365) {
    proseAge = 'one year';
  } else if (age < 3 * 365) {
    proseAge = '3 years';
  } else if (age < 5 * 365) {
    proseAge = '5 years';
  } else if (age < 7 * 365) {
    proseAge = '7 years';
  } else if (age < 10 * 365) {
    proseAge = '10 years';
  } else if (age < 15 * 365) {
    proseAge = '15 years';
  } else if (age < 20 * 365) {
    proseAge = '20 years';
  } else {
    proseAge = 'over 20 years'
  }

  scriptColData.value = proseAge;
  scriptColData.sort = age;
  scriptColData.group = proseAge;
}

ColumnAge.js.txt


How to use buttons and scripts from this forum

4 Likes