Quintiq file version 2.0
#parent: #root
Method SetDefaultValue () id:Method_DialogCreateEditProduct_SetDefaultValue
{
  #keys: '[135040.0.213300467]'
  Body:
  [*
    // Set default + init dialog
    dialogInstance := DataHolderDialogData.Data().WrappedInstance();
    isNew := isnull( dialogInstance );
    
    // Extract the parent product by filtering out the descendents of the selected products in order to prevent circularity
    products := construct( Product_MPs );
    if( isNew
        or dialogInstance.IsLeaf() ) // Is leaf
    {
      products := selectset( MacroPlan, Product_MP, p, true );
      currentScope := DataHolderDialogDatas.Data();
      
      products := products.Difference( currentScope );
    }
    else if( not dialogInstance.HasParent() ) // Is root level
    {
      products := selectset( MacroPlan, RootProduct, p, p <> dialogInstance );
    }
    else // Has Parent and Child
    {
      allProducts := selectset( MacroPlan, Product_MP, p, p <> dialogInstance );
      myChildren := selectset( dialogInstance, AllChildren.AsChildren, c, true );
    
      products := allProducts.Difference( myChildren );
    }
    
    DataHolderParentProductSelection.Data( products.Copy() );
  *]
}
