# \_setSchedule

Sets the contents for types of Schedules in a Recurring Job (Job Types, Stock, SoR)

### Parameters

#### id

The ID of the Recurring Job

#### val

A JSON-encoded string with various contents set for the Recurring Job

#### skip-run

An optional parameter which if set, skips the process of creating new jobs to adapt to changes in the Recurrence settings, which can be time-consuming.

### Examples

In this example, Job Types has 2 entries and Schedule of Rates has 1, skip-run is not set.\
Job Types for the 3rd and 6th instances of the Recurrence and Schedule of Rates for the 2nd instance.

"jobtype\_items" => A table of entries with both the recurrence number it is scheduled for and the Job Type id (e.g "6":"93775").\
"stock\_items" and "sor\_items" => A table of arrays indexed by their recurrence numbers, each with 3 variables:

* "num" => the amount
* "id" => the ID of the Stock Type/Schedule of Rates
* "price" => the price per item

Recurrence numbers always have a minimum value of 2.

```
FM_api('JobRecurrence_setSchedule',[
  'id'=>'429031',
  'val'=>json_encode([
    "jobtype"=>1,
    "jobtype_items"=>[
      "3"=>"152003",6=>"152003"
    ],
    "sor"=>1,
    "sor_items"=>[
      "2"=>"[{\"num\":3,\"id\":370001,\"price\":38}]"
    ]
  ])
  ]
);
```

This example includes 1 schedule of Stock for the 4th recurrence the job is scheduled for and 1 Schedule of Rates for the 3rd recurrence the job is scheduled for.

```
FM_api('JobRecurrence_setSchedule',[
  'id'=>'429027',
  'val'=>json_encode([
    "stock"=>1,
    "stock_items"=>[
      "4"=>"[{\"num\":250,\"id\":457355,\"price\":9}]"
    ],
    "sor"=>1,
    "sor_items"=>[
      "3"=>"[{\"num\":103,\"id\":370001,\"price\":12}]"
    ]
  ]),
  'skip-run'=>'1'
  ]
);
```

### Results

#### On Success

```
{"ok":1}
```

#### On Failure

If the "id" parameter is not set or has a value less than 1:

```
{"error":"missing or invalid parameter: id"}
```

If the "val" parameter is not set:

```
{"error":"missing or invalid parameter: val"}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fieldmotion.com/fieldmotion-api-docs/jobrecurrence/_setschedule.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
