Clearing Fields of Work Orders with the Tentative Status
When you deactivate a Real-Time Optimization dispatch process, the optimization job is marked IDLE immediately and no further optimization occurs. The tentatively scheduled work orders for the dispatch process are not considered for scheduling when the dispatch process is activated again.
To ensure that the tentatively scheduled work orders are considered for scheduling again after dispatch process activation and job initiation, you must clear the following Work Order fields manually:
SVMXC__Dispatch_Process__c
SVMXC__Group_Member__c
SVMXC__OptiMax_Status__c
SVMXC__Scheduled_Date_Time__c
SVMXC__FirstScheduledDateTime__c
SVMXC__Service_Group__c
SVMXC__Locked_By_DC__c
SVMXC__SM_Lock_Appointment_Schedule__c
SVMXC__Preferred_Start_Time__c
SVMXC__Preferred_End_Time__c
SVMXC__Order_Type__c
SVMXC__Order_Status__c
SVMXC__OptiMax_Error_Text__c
SVMXC__Scheduling_Change_Token__c
SVMXC__Dispatch_Status__c
SVMXC__Violation_Status2__c
SVMXC__Violation_Message__c
SVMXC__Work_Order_Scheduling_Status__c
Run the following script to clear the required Work Order fields:
datetime schDT = datetime.now().addDays(-40);
system.debug('scheduled date time > '+schDT);

List<SVMXC__Service_Order__c> OptiMaxWOs = [ select Id, Name, SVMXC__Dispatch_Process__c, SVMXC__Group_Member__c, SVMXC__OptiMax_Status__c, SVMXC__Primary_Territory__c, SVMXC__Scheduled_Date_Time__c, SVMXC__FirstScheduledDateTime__c, SVMXC__Service_Group__c, SVMXC__Locked_By_DC__c, SVMXC__SM_Lock_Appointment_Schedule__c, SVMXC__Preferred_Start_Time__c, SVMXC__Preferred_End_Time__c, SVMXC__Order_Type__c, SVMXC__Order_Status__c, SVMXC__OptiMax_Error_Text__c, SVMXC__Scheduling_Change_Token__c, SVMXC__Dispatch_Status__c, SVMXC__Violation_Status2__c, SVMXC__Violation_Message__c, SVMXC__Work_Order_Scheduling_Status__c from SVMXC__Service_Order__c where SVMXC__Dispatch_Status__c = 'Assigned' AND SVMXC__Primary_Territory__c ='a2C1U000001vBiP' AND SVMXC__Dispatch_Process__c != null AND SVMXC__Scheduling_Change_Token__c != null AND SVMXC__Scheduled_Date_Time__c > :schDT limit 50];
System.debug('WO List Size: ' + OptiMaxWOs.size());
Set<string> woIDs = new Set<string>();

for( SVMXC__Service_Order__c thisWO : OptiMaxWOs )
{
System.debug('WoId; WO Name; Scheduled DT: '+ thisWO.Id + ' ; ' + thisWO.Name+ ' ; ' +thisWO.SVMXC__Scheduled_Date_Time__c);


thisWO.SVMXC__Dispatch_Process__c=null;
thisWO.SVMXC__Group_Member__c=null;
thisWO.SVMXC__OptiMax_Status__c=null;
thisWO.SVMXC__FirstScheduledDateTime__c=null;
thisWO.SVMXC__Scheduled_Date_Time__c=null;
thisWO.SVMXC__Service_Group__c=null;
thisWO.SVMXC__Locked_By_DC__c=False;
thisWO.SVMXC__OptiMax_Error_Text__c=null;
thisWO.SVMXC__Violation_Status2__c=null;
thisWO.SVMXC__Scheduling_Change_Token__c= null;
thisWO.SVMXC__Work_Order_Scheduling_Status__c=null;
thisWO.SVMXC__Appointment_Promised_Time_Slot__c = null;
thisWO.SVMXC__SM_Lock_Appointment_Schedule__c = null;
thisWO.SVMXC__Violation_Message__c = null;

woIDs.add(thisWO.Id);
}
update OptiMaxWOs;

List<Event> sfEvents = [ select Id,Subject,WhatId,startDateTime from Event Where WhatId IN:woIDs ];
System.debug('Event Size: ' + sfEvents.size());
delete sfEvents;
List<SVMXC__SVMX_Event__c> svmxEvents = [ select Id from SVMXC__SVMX_Event__c where SVMXC__WhatId__c in :woIDs];
System.debug('SVMX Event Size: ' + svmxEvents.size());
delete svmxEvents ;
You must re-qualify the work orders for the dispatch process after clearing the scheduling-related fields using the script. Also, provide the appropriate SLA in work orders as per your business requirement.
Was this helpful?