Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Function CalcDisplayIndex 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    value := 0; 
 | 
    // For root element we will either increase from the last child of the previous root step display index 
 | 
    if( this.IsRootElement() 
 | 
        and not isnull( this.PreviousRootStepDefinition() ) ) 
 | 
    { 
 | 
    value := guard( this.PreviousRootStepDefinition().LastChildDefinition().DisplayIndex() + 1, 
 | 
                        this.PreviousRootStepDefinition().DisplayIndex() + 1 ); 
 | 
    } 
 | 
     
 | 
    // For non-root, we will increase from first sibling or from previous sibling last child..so on.. 
 | 
    else   
 | 
    { 
 | 
      value := guard( this.PreviousChildDefinition().LastChildDefinition().DisplayIndex() + 1, 
 | 
                      guard( this.PreviousChildDefinition().DisplayIndex() + 1, 
 | 
                             guard( this.ParentDefinition().DisplayIndex() + 1, 0 ) ) ); 
 | 
    } 
 | 
     
 | 
    this.DisplayIndex( [Number]value ); 
 | 
  *] 
 | 
} 
 |