This API uses two methods, getJob and setTerritory. getJob passes a job to setTerritory, and setTerritory applies a territoryID and groupPolicyID to that job via GroupData.
ScheduleJobsApi Methods
ScheduleJobsApi includes the following static methods.
getJob
Passes a scheduled job to thesetTerritory method, which modifies the territories.
Signature
global static ScheduleJobsApi getJob(String jobName)
Required. A list of GroupData objects representing the territories and group policies to be associated with the job.
Return Value
Type: Void
Usage
This method configures the Territory tab based on optimized territory and scheduling policy for a scheduled job. Here are two examples of code that configures the territory tab for a scheduled job.
Example 1:
1String jobName = 'Optimization';23List<FSL.ScheduleJobsApi.GroupData>groupList = new List<FSL.ScheduleJobsApi.GroupData>();45FSL.ScheduleJobsApi.GroupData firstGroup = new FSL.ScheduleJobsApi.GroupData6('a0cSM0000000fEU', new List<String>{'0HhSM0000000S5x', '0HhSM0000000TbV0AU'});78FSL.ScheduleJobsApi.GroupData secondGroup = new FSL.ScheduleJobsApi.GroupData9('0', new List<String>{'0HhSM0000000RbJ'});1011groupList.add(firstGroup);12groupList.add(secondGroup);1314FSL.ScheduleJobsApi.GetJob(jobName).setTerritory(groupList);
Example 2:
1String jobName = "Optimization";23// Get all service territory groups.4List<YourGroupType>All_ST_GROUPS = getAllGroupsFromAnotherSource();56List<FSL.ScheduleJobsApi.GroupData>groupList = new List<FSL.ScheduleJobsApi.GroupData>();78for(Integer i = 0; i<All_ST_GROUPS.size(); i++){9 FSL.ScheduleJobsApi.GroupData groupData = new FSL.ScheduleJobsApi.GroupData(10 All_ST_GROUPS[i].policyId,11 new List<String>{12 All_ST_GROUPS[i].territoryIds13}14);15 // Add the created groupData to the list.16 groupList.add(groupData);17}1819FSL.ScheduleJobsApi.GetJob(jobName).setTerritory(groupList);