1. Custom log of workflow course

    Article: AN0001927Updated: 23.09.2018

    Workflow creates a technical log of its course that is available to the administrator. This log contains a number of details but it is not suitable for a common user to whom we should display relevant information.

    Below picture contains record of a request with four key attributes. Request approval is performed in a workflow that is launched with the given record. The below master-detail relation tab displays user log of the workflow course.

    Below examples are real-life scripts from solutions Access Rights and Knowledge Base that are included in the package ObjectGears with models.

    Log entry after task is created

    The below script (besides assigning the task and linking a referred record to the task) creates a record in the class keeping data about workflow course and includes in it information about to whom and why the task was assigned. The script will also set a new status in he record with which it was launched.
    Where to use the script: Workflow Activity Task - Initialization script (generally any activity containing a field for a custom script)

    //Asigning the task to the role owner
    OGWFActualRun.ActualTaskAssignTo.Add( OGWFActualRun.Property.GetInteger( 'role-gestor'));

    //*Adding reference to the Request to the task
    OGWFActualRun.ActualTask.SetClassLink( 6721, OGWFActualRun.Property.GetInteger( 'request-id'));

    //Creating record in the class Request flow
    var clRF = OG.ClassDef.GetByCode( OGWFActualRun.ModelId, 'request-flow');
    var drNew= OG.DataRow.CreateNew( clRF.Id);
    drNew.SetClassLink( 6706, OGWFActualRun.Property.GetInteger('request-id'));
    drNew.SetDateTime( 6708, System.DateTime.Now);

    //determining Full name of the owner
    var p = OG.Person.GetById( OGWFActualRun.Property.GetInteger('role-gestor'));
    drNew.SetText( 6709, 'Request was submitted to the role gestor ' + p.FullName);

    OG.DataRow.SaveData( drNew);

    //set the request status to 2 - pending for approval
    var colStatus= OG.Column.GetByCode( OGWFActualRun.InputDataRow.ParentId, 'status');
    OGWFActualRun.InputDataRow.SetClassLink( colStatus.Id, 2);

    OG.DataRow.SaveData( OGWFActualRun.InputDataRow);

    Log entry after the task completion

    The below script creates a record in the class containing data about the workflow course and includes in it information whether the task was completed by request approval or rejection.
    Where to use the script: Workflow Activity Task - Script after user entry (generally any activity containing a field for a custom script)

    //Creating record in the class Request flow
    var clRF = OG.ClassDef.GetByCode( OGWFActualRun.ModelId, 'request-flow');
    var clT = OG.ClassDef.GetByCode( OGWFActualRun.ModelId, 'tasks');

    var colAppr = OG.Column.GetByCode( clT.Id, 'approval');
    var colComment = OG.Column.GetByCode( clT.Id, 'comment');

    var drNew= OG.DataRow.CreateNew( clRF.Id);
    drNew.SetClassLink( 6706, OGWFActualRun.Property.GetInteger('request-id'));
    drNew.SetDateTime( 6708, System.DateTime.Now);

    /* - Determine value from the column approval, class tasks (from the record that represented this task). */
    var column = OGWFActualRun.ActualTask.GetClassLink(colAppr.Id);
    var col_comment = OGWFActualRun.ActualTask.GetTextAsString(colComment.Id);

    var approval = 'rejected';
    if (column == 1)
    {
    approval = 'approved';
    OGWFActualRun.Property.SetBoolean( 'role-gestor-approval', true);
    }
    else
    {
    OGWFActualRun.Property.SetBoolean( 'role-gestor-approval', false);
    }

    if (col_comment == null || col_comment == '')
    {
    drNew.SetText( 6709, 'Request was ' + approval + ' by the role gestor.');
    }
    else
    { drNew.SetText( 6709, 'Request was ' + approval + ' by the role gestor with this comment: ' + col_comment + '.');
    }

    OG.DataRow.SaveData( drNew);

×