---
title: "Switch from the Entities client to the Jobs client"
slug: "switch-from-the-entities-client-to-the-jobs-client-1523397"
abstract: "How to replace calls that use EntitiesClient and QueryingClient with JobsClient when using the Web SDK."
---
# Switch from the Entities client to the Jobs client

With the introduction of a Jobs client, you need to replace the use of `EntitiesClient` and `QueryingClient` with `JobClient` when working with `M.Target` and `M.JobDescription` entities.

> [!note]
> To help you update your code to take advantage of the Jobs client, here are some more detailed [examples](https://doc.sitecore.com/ch/en/developers/cloud-dev/examples.html "Examples").

The following examples illustrate how to replace the use of `EntitiesClient` and `QueryingClient` with `JobClient` when using the Web SDK to work with `M.Target` and `M.JobDescription` entities.

## Fetch a Job description

Here is an example that retrieves a job description using the Entities client.

```csharp
// by id
IEntity entity = await _client.Entities.GetAsync(jobDescriptionId);

// by identifier
IEntity entity = await _client.Entitites.GetAsync(jobDescriptionIdentifier);

// by quering
Query query = Query.CreateQuery(entities =>
     from e in entities
     where e.DefinitionName == "M.JobDescription"
     select e);
IEntityQueryResult result = await _client.Querying.QueryAsync(query);
IList<IEntity> entities = result.Items;

```

To use the Jobs client, update the code as follows:

```text
IEntity entity = await _client.Jobs.GetDescriptionAsync(jobId);

```

## Save a job description

Here is an example that uses the Entities client.

```csharp
// create
IEntity entity = await MClient.EntityFactory.CreateAsync("M.JobDescripton");
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'new configuration'}"));
entity.GetRelation<IChildToOneParentRelation>("JobToJobDescription").Parent = jobId;
var entityId = await MClient.Entities.SaveAsync(entity);

// update
IEntity entity = await MClient.Entities.GetAsync(jobDescriptionId);
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'configuration'}"));
var entityId = await MClient.Entities.SaveAsync(entity);

```

To use the Jobs client, update the code as follows:

```csharp
// create
IEntity entity = await _client.EntityFactory.CreateAsync("M.JobDescripton");
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'configuration'}"));
var entityId = await _client.Jobs.SaveDescriptionAsync(jobId, entity);

// update
IEntity entity = await _client.Jobs.GetDescriptionAsync(jobId);
entity.SetPropertyValue("Job.Configuration", JToken.Parse("{'some': 'new configuration'}"));
var entityId = await _client.Jobs.SaveDescriptionAsync(jobId, entity);

```

## Delete a job description

Here is an example that uses the Entities client.

```text
await _entitiesClient.DeleteAsync(jobDescriptionId);

```

To use the Jobs client, update the code as follows:

```text
await _jobsClient.DeleteDescriptionAsync(jobId);

```

## Fetch a job target

Here is an example that uses the Entities client.

```csharp
// by id
IEntity entity = await _client.Entities.GetAsync(jobTargetId);

// by identifier
IEntity entity = await _client.Entitites.GetAsync(jobTargetIdentifier);

// by querying
Query query = Query.CreateQuery(entities =>
     from e in entities
     where e.DefinitionName == "M.Target"
       && e.Parent("JobToTarget") == jobId
       && e.Property("Target.State") == "Waiting"
     orderby e.CreatedOn descending
     select e);
IEntityQueryResult result = await _client.Querying.QueryAsync(query);
IList<Entity> entities = result.Items;

```

To use the jobs client, update the code as follows:

```csharp
JobTargetQuery request = new JobTargetQuery(jobId)
{
    State = "Waiting",
    Skip = 0,
    Take = 50,
    Cultures = new[] { new CultureInfo("en-US") }
};
IEntityCollectionResult result = await MClient.Jobs.GetTargetsAsync(request);
IList<IEntity> entities = result.Items;

```

## Save a job target

Here is an example that uses the Entities client.

```csharp
// create
IEntity entity = await _client.EntityFactory.CreateAsync("M.Target");
entity.SetPropertyValue("Target.Location", "some location");
entity.SetPropertyValue("Target.Data", JToken.FromObject(new
  {
      some = "data"
  }));
entity.GetRelation<IChildToOneParentRelation>("JobToTarget").Parent = jobId;
await _client.Entities.SaveAsync(entity);

// update
IEntity entity = await _client.Entities.GetAsync(targetId);
entity.SetPropertyValue("Target.Location", "new location");
await _client.Entities.SaveAsync(entity);

```

To use the Jobs client, update the code as follows:

```csharp
// create
IEntity entity = await _client.EntityFactory.CreateAsync("M.Target");
entity.SetPropertyValue("Target.Location", "some location");
entity.SetPropertyValue("Target.Data", JToken.FromObject(new
  {
      some = "data"
  }));
await _client.Jobs.SaveTargetAsync(jobId, entity);

// update
IEntityCollectionResult result =
    await _client.Jobs.GetTargetsAsync(new JobTargetQuery(jobId));
IEntity entity = result.Items.First();
entity.SetPropertyValue("Target.Location", "new location");
await _client.Jobs.SaveTargetAsync(jobId, entity);

```

## Delete a job target

Here is an example that uses the Entities client.

```text
await _client.Entities.DeleteAsync(targetId);

```

To use the Jobs client, update the code as follows:

```text
await _client.Jobs.DeleteTargetAsync(jobId, targetId);

```