ScheduleJobsApi Class

Represents configurations to the Territory tab that is available for all scheduled jobs that are categorized under Enhanced Optimization.

Namespace 

FSL

Usage 

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)

Parameters 

jobName

Type: String

Required. The name of the job to update for service territory. The job name is case-sensitive.

Return Value 

Type: ScheduleJobsApi(validateJobId(jobId))

Usage 

This method passes a job to setTerritory, which updates the Territory tab. See setTerritory for sample code.

setTerritory 

Sets territories for a job returned by getJob and performs various validation checks.

Signature 

public void setTerritory(List<GroupData> groupList)

Parameters 

groupList

Type: List<GroupData>

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';
2
3List<FSL.ScheduleJobsApi.GroupData> groupList = new List<FSL.ScheduleJobsApi.GroupData>();
4
5FSL.ScheduleJobsApi.GroupData firstGroup = new FSL.ScheduleJobsApi.GroupData
6    ('a0cSM0000000fEU', new List<String>{'0HhSM0000000S5x', '0HhSM0000000TbV0AU'});
7
8FSL.ScheduleJobsApi.GroupData secondGroup = new FSL.ScheduleJobsApi.GroupData
9    ('0', new List<String>{'0HhSM0000000RbJ'});
10
11groupList.add(firstGroup);
12groupList.add(secondGroup);
13
14FSL.ScheduleJobsApi.GetJob(jobName).setTerritory(groupList);

Example 2: 

1String jobName = "Optimization";
2
3// Get all service territory groups.
4List<YourGroupType> All_ST_GROUPS = getAllGroupsFromAnotherSource();
5
6List<FSL.ScheduleJobsApi.GroupData> groupList = new List<FSL.ScheduleJobsApi.GroupData>();
7
8for (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].territoryIds
13        }
14    );
15    // Add the created groupData to the list.
16    groupList.add(groupData);
17}
18
19FSL.ScheduleJobsApi.GetJob(jobName).setTerritory(groupList);