1. Case study Model IT: History class

    Article: AN0001839Updated: 06.02.2019

    There are several entities (Incident, Problem, Task..) in the model IT, where users shall record comment and time spent on resolution.

    Functionality description

    Users can comments in form of history showing date, user, comment and possibly hours spent on resolution for particular records.

    Only fields Comment and Time spent (hours) will be displayed to users. Fields Date, User and reference to entities Incident, Problem, Task... are hidden and filled in automatically. User can display history record that was saved before, with all columns but as read-only. If the record relates e.g. to entity Incident, other columns for references to other entities will be hidden.

    Solution description

    Comments from all entities will be saved in a single common history class. This enables easy reporting and possibility to easily add history for another class. Class History contains references to Incident, Problem, Task etc. in separate columns.

    We create a column of type Reference value in the class History for each class from which history shall be created. Relations of these classes are displayed in the following entity-relationship diagram.

     

    We create a master-detail relation for class History at each class from which comment shall be added. In this relation we check option Display button New and in Url variables for new record we set name of variable identifying the class with stating order of the variable in URL (e.g. inc={5} for class Incident). This enables to identify entity and record, from which the request was sent and fill in corresponding reference in the class History. Users can add new comment after clicking on button New in master-detail display.

    We will create a rule in the class History of type Before new record save, that will look for corresponding strings in URL (in the below stated example inc, pro, tsk) and according to that create in the history record reference to the appropriate record in the appropriate column.

    var isOk = false;
    var qs = System.Web.HttpContext.Current.Request.QueryString;
    var incId = Com.ObjectGears.Common.Helpers.ExtendMethod.GetInt( qs, 'inc');
    var proId = Com.ObjectGears.Common.Helpers.ExtendMethod.GetInt( qs, 'pro');
    var tskId = Com.ObjectGears.Common.Helpers.ExtendMethod.GetInt( qs, 'tsk');
    var uscId = Com.ObjectGears.Common.Helpers.ExtendMethod.GetInt( qs, 'usc');
    var reqId = Com.ObjectGears.Common.Helpers.ExtendMethod.GetInt( qs, 'req');

    //OG.Log.Write( incId + ' - ' + urpId);
    if ( incId != null)
    {
        var cl = OG.ClassDef.GetByCode( OGActualDataRow, 'incident');
        var drInc = OG.DataRow.GetDataById( cl.Id, incId);
        if ( drInc != null && !drInc.IsDeleted)
        {
            //zde není kontrola na toho, kdo to zapisuje!

            OGActualDataRow['incident'] = drInc.Id;
            isOk = true;
        }
    }
    else if ( proId != null)
    {
        var cl = OG.ClassDef.GetByCode( OGActualDataRow, 'problem');
        var drPro = OG.DataRow.GetDataById( cl.Id, proId);
        if ( drPro != null && !drPro.IsDeleted)
        {
             OGActualDataRow['problem'] = drPro.Id;
            isOk = true;
        }
    }
    else if ( tskId != null)
    {
        var cl = OG.ClassDef.GetByCode( OGActualDataRow, 'tasks');
        var drTsk = OG.DataRow.GetDataById( cl.Id, tskId);
        if ( drTsk != null && !drTsk.IsDeleted)
        {
             OGActualDataRow['task'] = drTsk.Id;
            isOk = true;
        }
    }
    else if ( uscId != null)
    {
        var cl = OG.ClassDef.GetByCode(  'requests', 'user_call');
        var drUsc = OG.DataRow.GetDataById( cl.Id, uscId);
        if ( drUsc != null && !drUsc.IsDeleted)
        {
             OGActualDataRow['user_call'] = drUsc.Id;
            isOk = true;
        }
    }
    else if ( reqId != null)
    {
        var cl = OG.ClassDef.GetByCode(  'requests', 'request');
        var drReq = OG.DataRow.GetDataById( cl.Id, reqId);
        if ( drReq != null && !drReq.IsDeleted)
        {
             OGActualDataRow['request'] = drReq.Id;
            isOk = true;
        }
    }

    if ( !isOk)
    {
        OGActualMessage.SetError( 'No reference to incident, problem nor task was provided.');
        return true;
    }

    We hide columns of the reference type, that do not hold actual reference, in the History class by means of a script for record detail:

    function OnPreRender()
    {
        var cinc = OGColumns.GetByCode('incident');
        var cpro = OGColumns.GetByCode('problem');
        var ctsk = OGColumns.GetByCode('task');
        var cusc = OGColumns.GetByCode('user_call');
        var creq = OGColumns.GetByCode('request');

        cinc.Visible = !(cinc.ColumnUI != null && ( cinc.ColumnUI.GetData() == null || cinc.ColumnUI.GetData().Count == 0) || OGDataRowId == null);
        cpro.Visible = !(cpro.ColumnUI != null && ( cpro.ColumnUI.GetData() == null || cpro.ColumnUI.GetData().Count == 0) || OGDataRowId == null);
        ctsk.Visible = !(ctsk.ColumnUI != null && ( ctsk.ColumnUI.GetData() == null || ctsk.ColumnUI.GetData().Count == 0) || OGDataRowId == null);
        cusc.Visible = !(cusc.ColumnUI != null && ( cusc.ColumnUI.GetData() == null || cusc.ColumnUI.GetData().Count == 0) || OGDataRowId == null);
        creq.Visible = !(creq.ColumnUI != null && ( creq.ColumnUI.GetData() == null || creq.ColumnUI.GetData().Count == 0) || OGDataRowId == null);

       if ( OGDataRowId == null)
       {
           OGColumns.GetByCode('date').Visible = false;
           OGColumns.GetByCode('og_user').Visible = false;
       }
    }

    (The example assumes that columns Incident, Problem, Task, User call and Request from the class History have checked the option Selection in the Search form.)

×