# Http request on save

<span class="mw-headline">This Codeunit is not ready for use!</span>

## <span class="mw-headline" id="bkmrk-what-it-does-1">What it does</span>

This codeunit is capable of performing an HTTP-request with parameters from the updated item and update the item based on the result.

## <span class="mw-headline" id="bkmrk-first-setup-1">First setup</span>

<span class="mw-headline">\[Optional, if extra config is required to get the codeunit working\]</span>

## <span class="mw-headline" id="bkmrk-how-to-invoke-1">How to invoke</span>

Add the codeunit `dk.tempusserva.codeunit.common.RequestFormevent` to the entity and add a configuration named `RequestFormevent.Setup` with content based on the following configuration.

It is possible to add both a "before-update" and an "after-update" action.

## <span class="mw-headline" id="bkmrk-configuration-1">Configuration</span>

<table class="wikitable" id="bkmrk-datapoint-%C2%A0-type-not"><tbody><tr><th>Datapoint</th><th> </th><th>Type</th><th>Notes</th></tr><tr><td>when</td><td>Required</td><td>String</td><td>Possible values: "after-update" or "before-update". Determines whether the call is executed before or after an item is updated.

</td></tr><tr><td>status</td><td>Optional</td><td>Array</td><td>An array of the StatusID's where the call should be executed. If "after-update", then this is if the item is in one of these status's after the update, likewise for "before-update".

If not given, then the call is executed every time.

</td></tr><tr><td>call</td><td>Required</td><td> </td><td>The actual configuration of the call.</td></tr><tr><td>call.url</td><td>Required</td><td>String</td><td>The url that is to be called. This supports input of parameters from the item.</td></tr><tr><td>call.method</td><td>Optional</td><td>String</td><td>The HTTP-method of the call, one of: "POST", "GET", "PUT" or "DELETE". Default: "GET".</td></tr><tr><td>call.type</td><td>Optional</td><td>String</td><td>The datatype of data returned, supported types: "json", "raw" or "XML". Default: "json".</td></tr><tr><td>call.headers</td><td>Optional</td><td>Map</td><td>A map of extra headers that should be set</td></tr><tr><td>call.params</td><td>Optional</td><td>Map</td><td>Path parameters that should be set and send.</td></tr><tr><td>call.body</td><td>Optional</td><td>String</td><td>A string that will be set and send. Not available for "GET".</td></tr><tr><td>call.update</td><td>Optional</td><td>Map</td><td>Fields that should be updated based on the data returned. If type is "raw", only the first item in this list will be updated, and it will be set to the entire response.

</td></tr></tbody></table>

### <span class="mw-headline" id="bkmrk-sample-1">Sample</span>

```json
[
    {
        "when": "before-update",
        "status": [69],
        "call": {
            "url": "https://acme.com/resource/[ID]",
            "method": "GET",
            "type": "json",
            "headers": {
                "Authorization": "Bearer XYZ"
            },
            "params": {
                "param": "[DATA]"
            },
            "body": "",
            "update": {
                "[LINK]": "info.link",
                "[NAME]": "info.name"
            }
        }
    }
]
```

## <span class="mw-headline" id="bkmrk-developer-info-1">Developer info</span>

- <span class="mw-headline">Type: [CodeunitFormevent](https://docs.tsnocode.com/books/codeunit-reference/chapter/formevents)</span>
- <span class="mw-headline">Security: requires session</span>
- <span class="mw-headline">Classpath: dk.tempusserva.codeunit.common.RequestFormevent</span>