1. Record approval by means of buttons

    Article: AN0002407Updated: 28.12.2019

    We need quite often to show that a certain record (requirement, invoice, task, project) was approved or rejected. Suitable solution is to use a column referring to a class that can contain values, Approved and Rejected, or Yes/No etc. When we use localized values, corresponding language variants of texts will be displayed. The user then selects these values from the combobox.

    We will show in the below example how we can improve this solution by approval by means of buttons that will be available only to the user that is defined in column 'responsible_for_assessment' as approver.

    We will set the column with status as read-only in the class detail (Script for list of records). At the same time we will display buttons for approval and rejection, only if the record does not have status 'closed' and if the column 'responsible_for_assessment' contains current user. Buttons will not be displayed to other users.

    function OnAfterLoadColumns()
    {
    OGColumns['status'].ReadOnly = true;
    }

    function OnPreRender()
    {
    OGColumns['responsible_for_assessment'].ColumnUI.ShowSelectMe = true;

    var colResponsible_for_assessment = OGClassDef.Columns['responsible_for_assessment'];
    var colStatus = OGClassDef.Columns['status'];
    var Responsible_for_assessment = OGForm.GetControl( colResponsible_for_assessment.Id).GetData();
    var status = OGForm.GetControl( colStatus.Id).GetData();

    //display buttons, if the status does not equal to closed (Id=4) and column responsible_for_assessment contains current user
    var Display = status != 4 // closed
    &&
    (Responsible_for_assessment != null && Responsible_for_assessment.Id == OG.Person.GetLoginPerson().Id)

    OGControlOperations['approve'].Visible = Display;
    OGControlOperations['reject'].Visible = Display;

    }

    We will also create two buttons with codes 'approve' and 'reject' in the given class.

    Button Approve will set the status to 'Approved' (Id=2).

    // Set Status to Approved and save
    var ht = OG.CreateHashtable();
    ht['status'] = 2;
    OGDataDetailForm.Save(false, ht);

    Button Reject will set the status to 'Rejected' (Id=3).

    // Set Status to Rejected and save
    var ht = OG.CreateHashtable();
    ht['status'] = 3;
    OGDataDetailForm.Save(false, ht);

     

×