Skip to content
import JobInfo from "@arcgis/core/rest/support/JobInfo.js";
Inheritance:
JobInfoAccessor
Since
ArcGIS Maps SDK for JavaScript 4.20

Represents information pertaining to the execution of an asynchronous geoprocessor request on the server.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

jobId

Property
Type
string

The unique job ID assigned by geoprocessing server.

jobStatus

Property
Type
JobStatus

The job status.

messages

autocast Property
Type
GPMessage[] | null | undefined

An array of messages that include a type and description.

progress

readonly Property
Type
ProgressorJSON | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.26

Displays the progress of the geoprocessing job. This value is only present when jobStatus is job-executing and is only updated every five seconds.

See also
Example
// Submit an asynchronous geoprocessing job
const jobInfo = await submitJob(url, params);
// Define a callback that will be called periodically. The function will print the
// geoprocessor's progress and percentage complete (if a step progressor).
const statusCallback = ({ jobStatus, progress }) => {
if (jobStatus !== "job-executing") { return; }
const { message, percent } = progress;
const status = `Message: ${message}
Progress: ${percent ?? "not specified"}`
console.log(`Status: ${status}`);
};
// Wait for the geoprocessing job to complete and print job progress
// to the console every five seconds
await jobInfo.waitForJobCompletion({ interval: 5000, statusCallback });

requestOptions

Property
Type
RequestOptions | null | undefined

The options to be used for data requests. These options can also be controlled through the requestOptions method parameter.

sourceUrl

Property
Type
string

ArcGIS Server Rest API endpoint to the resource that receives the geoprocessing request.

Methods

MethodSignatureClass
fromJSON
inherited static
fromJSON(json: any): any
cancelJob(requestOptions?: RequestOptions): Promise<JobInfo>
checkJobStatus(requestOptions?: RequestOptions | null): Promise<JobInfo>
destroy(): void
fetchResultData(resultName: string, gpOptions?: GPOptions | null, requestOptions?: RequestOptions | null): Promise<ParameterValue<any>>
fetchResultImage(resultName: string, imageParams: ImageParameters, requestOptions?: RequestOptions): Promise<ParameterValue<any>>
fetchResultMapImageLayer(): Promise<MapImageLayer>
toJSON
inherited
toJSON(): any
waitForJobCompletion(options?: WaitForJobOptions): Promise<JobInfo>

fromJSON

inheritedstatic Method
Signature
fromJSON (json: any): any
Inherited from: JSONSupportMixin

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameters
ParameterTypeDescriptionRequired
json
any

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
any

Returns a new instance of this class.

cancelJob

Method
Signature
cancelJob (requestOptions?: RequestOptions): Promise<JobInfo>

Cancels an asynchronous geoprocessing job. The returned promise will only resolve when the geoprocessing job has canceled on the server.

See also
Parameters
ParameterTypeDescriptionRequired
requestOptions

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns
Promise<JobInfo>

When resolved, returns a JobInfo.

Example
// Cancel an ongoing geoprocessing job when the user clicks a "cancel" button.
document.getElementById("cancelButton").addEventListener("click", () => {
jobInfo.cancelJob().then(() => {
console.log("Job cancelled successfully.");
}).catch(() => {
console.log("Problem occurred which cancelling the geoproccessing job");
});
});

checkJobStatus

Method
Signature
checkJobStatus (requestOptions?: RequestOptions | null): Promise<JobInfo>

Sends a request for the current state of this job.

Parameters
ParameterTypeDescriptionRequired
requestOptions

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns
Promise<JobInfo>

When resolved, returns a JobInfo.

destroy

Method
Signature
destroy (): void

Stop monitoring this job for status updates.

// Stop monitoring this job for status updates.
jobInfo.destroy();
See also
Returns
void

fetchResultData

Method
Signature
fetchResultData (resultName: string, gpOptions?: GPOptions | null, requestOptions?: RequestOptions | null): Promise<ParameterValue<any>>

Sends a request to the GP Task to get the task result identified by resultName.

Parameters
ParameterTypeDescriptionRequired
resultName

The name of the result parameter as defined in Services Directory.

gpOptions

Input options for the geoprocessing service return values.

requestOptions

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns
Promise<ParameterValue<any>>

When resolved, returns an object with a property named result of type ParameterValue, which contains the result parameters and the task execution messages.

fetchResultImage

Method
Signature
fetchResultImage (resultName: string, imageParams: ImageParameters, requestOptions?: RequestOptions): Promise<ParameterValue<any>>

Sends a request to the GP Task to get the task result identified by jobId and resultName as an image.

Parameters
ParameterTypeDescriptionRequired
resultName

The name of the result parameter as defined in the Services Directory.

imageParams

Specifies the properties of the result image.

requestOptions

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns
Promise<ParameterValue<any>>

When resolved, returns an Object with a mapImage property of type MapImage

fetchResultMapImageLayer

Method
Signature
fetchResultMapImageLayer (): Promise<MapImageLayer>

Get the task result identified by jobId as an MapImageLayer.

Returns
Promise<MapImageLayer>

A promise resolving to an instance of MapImageLayer.

Example
// Get the resulting map image layer from a completed geoprocessing job.
jobInfo.fetchResultMapImageLayer(jobInfo.jobId)).then(function(layer){
view.map.add(layer);
});

toJSON

inherited Method
Signature
toJSON (): any
Inherited from: JSONSupportMixin

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
any

The ArcGIS portal JSON representation of an instance of this class.

waitForJobCompletion

Method
Signature
waitForJobCompletion (options?: WaitForJobOptions): Promise<JobInfo>

Resolves when an asynchronous job has completed. Optionally job progress can be monitored.

Parameters
ParameterTypeDescriptionRequired
options

Options. See properties below for object specifications.

Returns
Promise<JobInfo>

When resolved, returns a JobInfo.

Example
// Submit an asynchronous geoprocessing job. Display the remote job status every 1.5 seconds.
// When the job has completed, the output is a MapImageLayer.
const startDate = "1998-01-01 00:00:00";
const endDate = "1998-05-31 00:00:00";
const params = {
query: "(Date >= date '" + startDate + "' and Date <= date '" + endDate + "')"
};
const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/911CallsHotspot/GPServer/911%20Calls%20Hotspot";
submitJob(url, params).then((jobInfo) => {
const jobid = jobInfo.jobId;
console.log("ArcGIS Server job ID: ", jobid);
const options = {
interval: 1500,
statusCallback: (j) => {
console.log("Job Status: ", j.jobStatus);
}
};
jobInfo.waitForJobCompletion(options).then(() => {
const layer = jobInfo.fetchResultMapImageLayer.then(function(layer){
map.add(layer);
});
});
});