| Quintiq file version 2.0 | 
| #parent: #root | 
| Method MPSyncLaneLeg ( | 
|   Boolean isoverwritemanualconfig, | 
|   IOLane iolane, | 
|   Lane mplane | 
| ) | 
| { | 
|   Description: 'Synchronization of LaneLeg for MPSync' | 
|   TextBody: | 
|   [* | 
|     // Select a set of existing LaneLeg | 
|     existing := selectset( mplane, LaneLeg, item, true ); | 
|     updates := construct( LaneLegs ); | 
|      | 
|     // Traverse the new set of valid LaneLeg | 
|     traverse( iolane , IOLaneLeg, io, io.IsValid() ) | 
|     { | 
|       orispid := io.OriginStockingPointID(); | 
|       destspid := io.DestinationStockingPointID(); | 
|       // Find existing LaneLeg | 
|       objectinstance := LaneLeg::FindLaneLegTypeIndex( mplane.ID(), orispid, destspid ); | 
|        | 
|       // If no existing LaneLeg is found, and the passed in Lane is not null, create one | 
|       if( isnull( objectinstance ) ) | 
|       { | 
|         if( not isnull( mplane ) ) | 
|         { | 
|           objectinstance := LaneLeg::Create( mplane, | 
|                                              orispid, | 
|                                              destspid, | 
|                                              io.IsEnabled(), | 
|                                              io.Start(), | 
|                                              io.End(), | 
|                                              io.Name(), | 
|                                              io.HasUserLeadTime(), | 
|                                              io.UserLeadTime(), | 
|                                              io.HasStandardDeviationLeadTimeLaneLeg(), | 
|                                              io.StandardDeviationLeadTimeLaneLeg(), | 
|                                              io.PreferenceBonus(), | 
|                                              io.CO2Emission(), | 
|                                              true ); | 
|         }  | 
|       } | 
|       // Else if the LaneLeg is not manually configured or the imported instance should overwrite manual configuration, | 
|       // update the existing LaneLeg | 
|       else if( not objectinstance.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|       { | 
|         // Update LaneLeg | 
|         if( not isnull( mplane ) ) | 
|         { | 
|           objectinstance.Update( orispid, | 
|                                  destspid, | 
|                                  io.IsEnabled(), | 
|                                  io.Start(), | 
|                                  io.End(), | 
|                                  io.Name(), | 
|                                  io.HasUserLeadTime(), | 
|                                  io.UserLeadTime(), | 
|                                  io.HasStandardDeviationLeadTimeLaneLeg(), | 
|                                  io.StandardDeviationLeadTimeLaneLeg(), | 
|                                  io.PreferenceBonus(), | 
|                                  io.CO2Emission(), | 
|                                  true ); | 
|           updates.Add( objectinstance ); | 
|         } | 
|       } | 
|        | 
|       // Extended method | 
|       if( not isnull( objectinstance ) ) | 
|       {   | 
|         objectinstance.CustomUpdate( io, isoverwritemanualconfig ); | 
|       } | 
|     } | 
|      | 
|     // Get the set of old LaneLeg to be deleted | 
|     tobedeleteset := existing.Difference( updates ); | 
|      | 
|     // Traverse the set of LaneLeg to be deleted | 
|     // Only delete LaneLeg that is not manually configured or the imported instance should overwrite manual configuration | 
|     traverse( tobedeleteset, Elements, ele, | 
|               not ele.IsManuallyConfigured() or isoverwritemanualconfig ) | 
|     { | 
|       ele.Delete(); | 
|     } | 
|   *] | 
| } |