1. Script for updating values in record according to other columns

    Artikel: AN0002408Aktualisiert: 15.01.2020
    Die vorgegebene Sprachenversion vom Artikeltext wird angezeigt, weil es kein Text von der ausgewählten Sprache und Version gibt.

    In the below example we are using class Changes (change), that contains among others:

    1. column Locality (locality) - column type: simple reference to another class
    2. column Approver (responsible for assessment) - column type: simple reference to a user

    Further we have class Locality (locality), that contains among others:

    1. column Name (name) - column type: text, not important in the example below
    2. column Approver (responsible for assessment) - column type: simple reference to a user

    Data scheme is following.

    When creating a new record the user can either fill in the Approver (then this one will be used) or can leave the field blank (and then the application will update the field with the person according to the class locality - there is an approver defined for each locality).

    Everything will be secured by a rule of type Script in an event Before saving a new record in the class Changes (change).

    The goal is to assign a person at the time of record creation, if the person was not defined by the user, that will be responsible for assessment, according to the locality.
    It is OG user that is stated in column responsible_for_assessment in the class locality.

    if (OG.IsNull(OGActualDataRow['responsible_for_assessment']))
      var locality = OGActualDataRow.GetDR('locality');
      var colCh_Lo = OG.Column.GetByCode( OGActualDataRow, 'locality');

      var locId = OGActualDataRow.GetClassLink(colCh_Lo.Id);
      if ( locId != null)
        var clLoc = OG.ClassDef.GetByCode( OGActualDataRow, 'locality');

        var dr = OG.DataRow.GetDataById( clLoc.Id, locId);
        if ( dr != null)
          var colResp = OG.Column.GetByCode( clLoc.Id , 'responsible_for_assessment');
          var resp = dr.GetPerson( colResp.Id);
          if ( resp != null)
            var colCh_Resp = OG.Column.GetByCode( OGActualDataRow, 'responsible_for_assessment');
            OGActualDataRow.SetPerson( colCh_Resp.Id, resp);