Gutis

ObjectX activity log

Blog Post created by Gutis Champion on Sep 19, 2015

It seems that CA team is using one trigger to write activitys to act_log:

POST_CI val_fieldupdate( persistent_id, audit_userid,CHANGED_ONLY, "UI_INFO_ATTRS AUDIT_FLAG UI_INFO_ATTRS AUDITLOG")  20006  FILTER( EVENT("UPDATE") );

I decided to reuse it for logging my ObjectX activities.

First of all I have created table wich will store activity log information:

 

///////////////////////////////////////////////////////////////////////
// Factory:   zoalg
// Description: Fac_Attr_Entry zoalg
////////////////////////////////////////////////////////////////////////

OBJECT zoalg {
  ATTRIBUTES zoalg {
    action_desc STRING 4000
      WRITE_NEW;
    analyst SREL cnt
      WRITE_NEW SERVICE_PROVIDER_ELIGIBLE
      {
      ON_NEW DEFAULT USER;
      };
    description STRING 4000;
    internal INTEGER
      {
      ON_NEW DEFAULT 0;
      };
    objectx_id SREL zobjectx
      WRITE_NEW REQUIRED
      DISPLAY_NAME "objectx id";
    system_time DATE
      WRITE_NEW
      DISPLAY_NAME "system time"
      {
      ON_NEW DEFAULT NOW;
      };
    time_spent DURATION
     
      DISPLAY_NAME "time spent";
    time_stamp DATE
     
      DISPLAY_NAME "time stamp"
      {
      ON_NEW DEFAULT NOW;
      };
    type SREL aty
      WRITE_NEW REQUIRED;
    last_mod_dt DATE { ON_CI SET NOW; };
    last_mod_by SREL cnt { ON_CI SET USER;
                           ON_NEW DEFAULT USER; };
  };

  FACTORY zoalg {
    STANDARD_LISTS {
      MLIST OFF;
      RLIST OFF;
    };
    FUNCTION_GROUP "OBJX";
    REL_ATTR id;
    COMMON_NAME description;
  };
};

 

To be able to use trigger unchanged i added LOCAL atribute audit_userid to my ObjectX and added additional display group in order to be able to create activity association for ObjectX

Now my objectx.mod has the following content

////////////////////////////////////////////////////////////////////////
// Factory:   zobjectx (objectx)
// Description: Fac_Attr_Entry zobjectx
////////////////////////////////////////////////////////////////////////

OBJECT zobjectx {
ATTRIBUTES zobjectx {
        audit_userid LOCAL  SREL cnt TENANCY_UNRESTRICTED {
                                ON_NEW DEFAULT USER ;
                                ON_CI SET USER ;
                            } ;
  };
  FACTORY zobjectx {
    DISPLAY_GROUP "stored_query act_log";
  //domset used for user scoreboard counts
    DOMSET scoreboard_user_bin "id" "" DYNAMIC ;
  };
  TRIGGERS {
POST_CI val_fieldupdate( persistent_id, audit_userid,CHANGED_ONLY, "UI_INFO_ATTRS AUDIT_FLAG UI_INFO_ATTRS AUDITLOG")  20006  FILTER( EVENT("UPDATE") );
};

};

 

In order to create activity associations i have modified detail_act_type_assoc.htmpl, file attached. I also created association for my description field:

 

 

And here is my val_fieldupdate function:

zobjectx::val_fieldupdate(...)
{
int j;
logf(ERROR, "parameter no: '%s'", argc);
if (argc>6){
for (j=0;j<(argc);j=j+1) {
    logf(ERROR, "parameter: '%s' equal to: '%s'",j,argv[j]);   
  }
}
return;
}

 

I have added +AUDITLOG() UI_INFO for description and customer attributes

 

 

Recycled SDM services

After that changed descriptio, customer and requester attribute values for one of my ObjectX record. This is what i got in my log

 

parameter no: '13'

6 parameter: '0' equal to: '3'

6 parameter: '1' equal to: 'persistent_id'

6 parameter: '2' equal to: 'zobjectx:400001'

6 parameter: '3' equal to: 'zobjectx:400001'

6 parameter: '4' equal to: 'audit_userid'

6 parameter: '5' equal to: ''

6 parameter: '6' equal to: '70735EDD6CF3264D9B6976CDC095015F'

6 parameter: '7' equal to: 'customer'

6 parameter: '8' equal to: '20AB02D29AA8414FB3BE2F3CEB2E9FEC'

6 parameter: '9' equal to: '70735EDD6CF3264D9B6976CDC095015F'

6 parameter: '10' equal to: 'description'

6 parameter: '11' equal to: 'Object X first test for log5'

6 parameter: '13' equal to: 'Object X first test for log6'

 

then i have changed only customer field:

 

parameter no: '10'

6 parameter: '0' equal to: '3'

6 parameter: '1' equal to: 'persistent_id'

6 parameter: '2' equal to: 'zobjectx:400001'

6 parameter: '3' equal to: 'zobjectx:400001'

6 parameter: '4' equal to: 'audit_userid'

6 parameter: '5' equal to: ''

6 parameter: '6' equal to: '70735EDD6CF3264D9B6976CDC095015F'

6 parameter: '7' equal to: 'customer'

6 parameter: '8' equal to: '20AB02D29AA8414FB3BE2F3CEB2E9FEC'

6 parameter: '9' equal to: '70735EDD6CF3264D9B6976CDC095015F'

 

Ok so i have persisten_id of my objectX, userid of the person who did the change, and most important i have all  names, previous and curent values for changed auditable fields (+AUDITLOG())

 

 

So now all i need to do is to write spell code, that will get all changes, will check if there is related activity assocciation for the changed field, if association is nod found will create generic field update activity in other case will create activity that is defined there.

Outcomes