Quintiq file version 2.0
#parent: #root
Method NewCampaign (
  internal[GUIComponent] parent,
  CampaignType_MP campaigntype,
  Unit owner
) as Campaign_MP id:Method_DialogCreateEditCampaign_MP_NewCampaign
{
  #keys: '[110880.4.851635701]'
  Body:
  [*
    // New campaign
    
    if( isnull( campaigntype ) )
    {
      campaigntype := Campaign_MP::GetDefaultCampaignType( owner );
    }
    
    data := owner.Campaign_MP( relshadow, UnitID := owner.ID(), 
                                          CampaignID := "", // Temporary set CampaignID to empty, will be defined during creation
                                          InputType := campaigntype.InputType() ); // Create will default to campaign type input type
    
    Dialog.Data( data );
    Dialog.SetDefaultValue( campaigntype );
    ValueHolderCampaignAddToLast.Data( true );
    this.InitializeDialog();
    this.SetIndicatorValue();
    
    result := Dialog.DoModal( parent );
    newobj := null( Campaign_MP );
    if( result > 0 )
    {
      campaignid := OS::GenerateGUIDAsString();
      newobj := Campaign_MP::Create( SelectionCampaignType.Data().Unit(),
                                     data.EarliestStart(),
                                     data.SequenceNumberForExcel(),
                                     data.MinQuantity(),
                                     data.MaxQuantity(),
                                     data.MinDuration(),
                                     data.MaxDuration(),
                                     SelectionCampaignType.Data().Name(),
                                     campaignid,
                                     data.Comment(),
                                     data.HasInputMaxQuantity() and RadioButtonGroupQuantityDuration.BoundValue() = GlobalParameters_MP::GetCampaignTransitionsTypeQuantity(),
                                     data.HasInputMaxDuration() and RadioButtonGroupQuantityDuration.BoundValue() = GlobalParameters_MP::GetCampaignTransitionsTypeDuration(),
                                     false );
              }
    return newobj;
  *]
}
