Version:
  1. Script for a read-only column

    Article: AN0001915 Displayed: 943x

    The fact that the column should be read-only is primarily defined in column detail. However, if we want to set up read-only column depending on other facts, we need to enable editing in the column detail and set up the read-only property at the runtime.

    The below script will set up column 'date' as read-only.

    Where to use the script: Class detail: Script for record detail

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

    The below script will set up for an existing record (not for a newly created and not for an archived record) all columns except for column 'comment' as read-only, if the current user is not in column 'solver' or if the user does not have one of roles 'it-architect', 'system-administrator', 'it-helpdesk'.

    Where to use the script: Class detail: Script for record detail

    function OnAfterLoadColumns()
    {
      var isRow = OGDataRowId != null;

      if ( isRow && !OGIsArchiveMode)
      {
        var isRight = false;

        if (
            OG.Person.IsUserInRoleByCode('it-helpdesk') ||
            OG.Person.IsUserInRoleByCode('it-architect') ||
            OG.Person.IsUserInRoleByCode('system-administrator')
            )
        {
          isRight = true;
        }

        if ( !isRight)
        {
          var dr = OG.DataRow.GetDataById(OGClassDef.Id, OGDataRowId);
          if ( dr != null && dr['solver'] != null && dr['solver'].Id == OG.Person.GetLoginPerson().Id)
          {
            isRight = true;
          }
        }
        //pokud nema roli ani neni resitelem, tak vse zakazat krome sloupce comment
        if( !isRight)
        {
          var colIds = OGColumns.GetColumnIds();
          for( var i = 0; i < colIds.Count; ++i)
          {
            var cc = OGColumns.GetById(colIds[i]);
            if ( cc.Entity.Code != 'comment')
            {
              cc.ReadOnly = true;
            }
          }
        }
      }
    }

  2.    ---
    Your rating:
    Rated by users: 0x
  3. Top
SearchTitle
×