[Audit]: Retrieving User Account Details

This is an example of how to retrieve User Account Details from the Ambience Server using an Object Data Source created using Ambience Data Designer. The data source can then be used to create an audit listing report if required.

Notes:
// This example is tested on Ambience 4.6.2

Retrieving User Account Details

  1. Add a new Object Data Source.

  2. At “Enter datasource name and define the schema” section, add 5 new columns with the respective data types as follows:
    image

  3. At “View/Edit the JavaScript initializing the data source” section, add the following script:

    importClass(Packages.com.elixirtech.arch.job.JobLogging);
    importClass(Packages.com.elixirtech.usergroup.UserGroupUtil);

    function pushTo(/*PushContext*/ cxt, /*DataListener*/ dl)
    {
      JobLogging.logInfo("AmbienceUsers","Calling server");
      var users = UserGroupUtil.getUsers();
      JobLogging.logInfo("AmbienceUsers","Got " + users.length + " users");
      dl.startData(this);
      for (i=0;i<users.length;i++) {
        var rec = this.newRecordInstance();
        var data = rec.getData();
        data[0] = users[i].name();
        data[1] = users[i].email();
        data[2] = UserGroupUtil.getExtra(users[i],"userID","");
        data[3] = users[i].groups().mkString(",");
        data[4]=users[i].enabled();
        dl.processRecord(rec);
      }
      dl.endData(this);
    }
  1. Click Finish once done.

  2. Generate the data by right-clicking the data source / click on the “Load Data” icon.

Retrieving User’s Last Login Date & Time

  1. Add a new Object Data Source.

  2. At “Enter datasource name and define the schema” section, add 2 new columns with their respective data types as follows:
    image

  3. At “View/Edit the JavaScript initializing the data source” section, add the following script:

    function pushTo(/*PushContext*/ cxt, /*DataListener*/ dl)
    {
      dl.startData(this);
      var info = com.elixirtech.v2.jobengine.bridge.UserGroupInfo.getLastLogins();
      var calendar = java.util.Calendar.getInstance();
      for (var i=0;i<info.length;i++) {
        var rec = this.newRecordInstance();
        var data = rec.getData();
        data[0] = info[i].user();
        var ts = info[i].ts();
        if (ts.isDefined()) {
          calendar.setTimeInMillis(ts.get())
          data[1] = calendar.getTime();
        }
        dl.processRecord(rec);
      }
  dl.endData(this);
}
  1. Click “Finish” once done.

  2. Generate the data by right-clicking the data source / click on the “Load Data” icon.

Reference for the above example can be downloaded here:
obj_ds.zip (1.6 KB)