# observe\_rsc\_update/3

Source: https://zotonic.com/docs/2052/observe_rsc_update-3

URI: https://zotonic.com/id/2052

Language: en



An updated resource is about to be persisted. Observe this notification to change the resource properties before they are persisted.

The props are the resource’s props *before* the update, but *after* filtering and sanitization. The folded value is `{ok, UpdateProps}` for the update itself.

Type:

[foldr](/id/doc_developerguide_notifications#notification-foldr)

Return:

`{ok, UpdateProps}` or `{error, term()}`

`#rsc_update{}` properties:

- action: `insert|update`
- id: `m_rsc:resource_id()`
- props: `m_rsc:props()`

An updated resource is about to be persisted. Observe this notification to change the resource properties before they are persisted.

Arguments
---------

`#rsc_update`

`action`

Either `insert` or `update`.

`id`

Id of the resource.

`props`

Map with resource properties.

`{ok, UpdateProps} | {error, Reason}`

And/remove resource properties before the update is persisted.

`Context`

Site context

Example
-------

Add a property before the resource is persisted:

```erlang
observe_rsc_update(#rsc_update{action = insert, id = Id}, {ok, Props}, Context) ->
    %% Set an extra property
    {ok, Props#{ <<"extra_property">> => <<"special value!">> }}.
observe_rsc_update(#rsc_update{action = insert, id = Id}, {error, _} = Error, Context) ->
    Error.
```

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2052?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2052?language=en>)
