| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod CreateDemandManagementMessage ( | 
|   MacroPlan macroplan | 
| ) | 
| { | 
|   Description: 'Create sanity check message for demand management' | 
|   TextBody: | 
|   [* | 
|     // Get the limit for number of sanity check messages | 
|     messagelimit := macroplan.GlobalParameters_MP().SanityCheckLimit(); | 
|      | 
|     // Get SalesDemandInPeriods that has sanity check violation(s) | 
|     invalidobjects := selectsortedset( macroplan,  | 
|                                        SanityCheckGroup.astype( SanityCheckGroupDemandManagement ).InvalidBaseSalesDemandInPeriod,  | 
|                                        invalidobject, | 
|                                        true, | 
|                                        invalidobject.SanityCheckDemandManagementMostSevere() ); | 
|      | 
|     objcount := 0; | 
|     // Traverse the set of SalesDemandInPeriods and create sanity check message | 
|     // as long as the number of SalesDemandInPeriods processed doesn't exceed the limit of number of messages | 
|     traverse( invalidobjects, | 
|               Elements, | 
|               invalidobject, | 
|               objcount <= messagelimit ) | 
|     { | 
|       objcount := objcount + 1; | 
|        | 
|       feedbacks := construct( Strings ); | 
|       sanitycheckfeedbacks := construct( Strings ); | 
|        | 
|       // Get sanity check violation messages and categories | 
|       invalidobject.DoSanityCheckDemandManagement( feedbacks, sanitycheckfeedbacks ); | 
|      | 
|       i := 0; | 
|       // Traverse each sanity check violation categories | 
|       traverse( sanitycheckfeedbacks,  | 
|                 Elements,  | 
|                 scfb ) | 
|       { | 
|         // Check if there're any SanityCheckMessageDemandManagement with the same description, if there's none, create one | 
|         if( not exists( invalidobject, SanityCheckMessageDemandManagement, msg, msg.Description() = scfb ) ) | 
|         { | 
|           //tokenize msg to retrieve category level and seperate the actual feedback | 
|           sanitycheckmessage := SanityCheckMessageDemandManagement::Create( invalidobject.SanityCheckGroupDemandManagement(), | 
|                                                                             feedbacks.Element( i ), | 
|                                                                             true, | 
|                                                                             scfb ); | 
|           sanitycheckmessage.BaseSalesDemandInPeriod( relset, invalidobject ); | 
|         } | 
|         i := i + 1; | 
|       } | 
|        | 
|         | 
|     } | 
|   *] | 
| } |