1. Value transfer to a new record from master detail relation

    Article: AN0002409Updated: 18.01.2020

    In some cases we need to transfer data from the referred record when creating a new record from a master-detail relation.

    In the below example we have a class Project, that contains among others column Primary goal (primary_goal) and column Modified configuration items (modified-ci). These columns are highlighted together with a button for creating a new record in the master-detail relation in the below print screen.

     

     

    Our goal is to open a new record of Task after clicking on he button New, which will refer to the given Project and will contain in columns Goal and Modified items values from the project - exactly as we see it in the below print screen.

     

    There is entity-relationship diagram showing columns relevant for our example for more clarity:

    To achieve this behaviour we will set up in the corresponding master-detail relation of the class Project a variable, that will be added to URL and that will be identified in the rule Before displaying a new record in the detail of the class Task.

    We will set property Url variables for new record to "com=goal".

    Rule of type Script of the event  Before displaying new record in detail:

    var com = OG.QueryString.GetString('com');
    var proId = OG.QueryString.GetInt('Fi1v');

    if ( com == 'goal' && proId != null)
    {
      var clPro = OGDataParent.Model.ClassDefs['project'];
      var drPro = OG.DataRow.GetDataById( clPro.Id, proId);

      if ( drPro != null)
      {
        //read Primary goal
        var id = drPro['primary_goal'];
        if ( id != null)
        {
          var clGoal = OGDataParent.Model.ClassDefs['goal'];
          OGActualDataRow['goal'] = OG.DataRow.GetDataById(clGoal.Id, id);
        }

        //read Modified configuration items
        var clCi = OGDataParent.Model.ClassDefs['ci'];
        var cis = drPro['modified-ci'];
        if ( cis != null && cis.Count > 0)
        {
          //OGActualDataRow['modified-ci'] = OG.DataRow.GetDataById(clCi.Id, cis[0].Id);

          OGActualDataRow['modified-ci'].AddRange(cis);
        }
      }
    }

×