# Récupérer un paramètre d'action depuis le hook actionService d'un ObjectService

**URL:** <https://community.simplicite.io/t/recuperer-un-parametre-daction-depuis-le-hook-actionservice-dun-objectservice/6977>\
**Category:** Support\
**Tags:** v5\
**Created:** [October 5, 2023, 8:56am UTC](https://community.simplicite.io/t/recuperer-un-parametre-daction-depuis-le-hook-actionservice-dun-objectservice/6977 "2023-10-05T08:56:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmo](https://community.simplicite.io/letter_avatar_proxy/v4/letter/b/9de0a6/32.png) [@bmo](https://community.simplicite.io/u/bmo)\
**Post date:** [October 5, 2023, 8:56am UTC](https://community.simplicite.io/t/recuperer-un-parametre-daction-depuis-le-hook-actionservice-dun-objectservice/6977/1 "2023-10-05T08:56:07Z")

</div>

### Request description

Je n’arrive pas à récupérer la valeur d’un paramètre d’action (via getConfirmField) depuis le hook actionService d’un ObjectService.

J’ai essayé sans succès diverses combinaisons pour placer l’appel à getConfirmField selon les options documentées dans le javadoc. Le retour de getConfirmField est null.

### Steps to reproduce

```java
public class GcsDocument extends ObjectService {
	private static final long serialVersionUID = 1L;
	...
	@Override
	public Object actionService(String action) {
		if ("pgDump".equals(action)) {
			String module = /*getAction(action).getConfirmField(this.getGrant().getLang(), "gcsPgModuleName").getValue()*/"IT4itGuest_AS0";
			...
			return ...;
		}
		return null;
	}

```

```java
<?xml version="1.0" encoding="UTF-8"?>
<simplicite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.simplicite.fr/base" xsi:schemaLocation="http://www.simplicite.fr/base https://www.simplicite.io/resources/schemas/base.xsd">
<object>
	<name>Action</name>
	<action>upsert</action>
	<data>
		<act_name>pgDump</act_name>
		...
	</data>
</object>
...
<object>
	<name>ActionField</name>
	<action>upsert</action>
	<data>
		<afd_action_id.act_name>pgDump</afd_action_id.act_name>
		<afd_field_id.fld_name>gcsPgModuleName</afd_field_id.fld_name>
		...
	</data>
</object>
</simplicite>

```

### Technical information

> **Instance /health**
>
> ```plaintext
> [Platform]
> Status=OK
> Version=5.2.48
> BuiltOn=2023-09-22 15:35
> Git=5.2/26c5dc03acbec92dd5eb0f3ec3d98782e048522b
> 
> ```

> **Simplicité logs**
>
> ```plaintext
> ---paste the content of the **relevant** server-side logs---
> 
> ```

> **Browser logs**
>
> ```plaintext
> ---paste content of the **relevant** browser-side logs---
> 
> ```

> **Other relevant information**
>
> _----E.g. type of deployment, browser vendor and version, etc.----_

---

<div class="post-metadata">

**Author:** ![david](https://community.simplicite.io/user_avatar/community.simplicite.io/david/32/5703_2.png) [@david](https://community.simplicite.io/u/david)\
**Post date:** [October 5, 2023, 1:25pm UTC](https://community.simplicite.io/t/recuperer-un-parametre-daction-depuis-le-hook-actionservice-dun-objectservice/6977/2 "2023-10-05T13:25:46Z")

</div>

Je ne pense pas avoir déjà mis en place une action avec paramètres sur un objet service.  
Je vais tester ce cas et je te tiens au courant.

Le hook `actionService` des objets service a été mis en place il y a longtemps, lui passer en paramètre le nom de l’action plutôt que l’action elle même n’est sans doute plus idéal.

---

<div class="post-metadata">

**Author:** ![david](https://community.simplicite.io/user_avatar/community.simplicite.io/david/32/5703_2.png) [@david](https://community.simplicite.io/u/david)\
**Post date:** [October 10, 2023, 1:06pm UTC](https://community.simplicite.io/t/recuperer-un-parametre-daction-depuis-le-hook-actionservice-dun-objectservice/6977/3 "2023-10-10T13:06:49Z")

</div>

Bon, après analyse la manière dont c’était implémenté dans le cas des objets service n’allait globalement pas.

Le hook `actionService` sert désormais uniquement (comme ça aurait dû être le cas depuis toujours) à surcharger, si besoin, la mécanique d’appel des actions (et pour s’aligner sur ce qu’on fait par ailleurs elle prend désormais en paramètre l’action et plus simplement le nom de l’action).

Mais pour les cas plus simples ça marche désormais comme pour toute action =\> si le hook `actionService` n’est pas implémenté, ça fait comme pour tout objet, ça appelle la méthode paramétrée dans l’action (avec accès aux paramètres si besoin), ex:

```java
	@BusinessObjectAction
	public String testAction(Action action) {
		ObjectField p = action.getConfirmField(getGrant().getLang(), "testParam");
		return Message.formatSimpleText("Hello " + p.getValue() + " world!");
	}

```

Ce sera livré dans le cadre de la prochaine révision 5.3.18

---

<div class="post-metadata">

**Author:** ![david](https://community.simplicite.io/user_avatar/community.simplicite.io/david/32/5703_2.png) [@david](https://community.simplicite.io/u/david)\
**Post date:** [October 10, 2023, 1:12pm UTC](https://community.simplicite.io/t/recuperer-un-parametre-daction-depuis-le-hook-actionservice-dun-objectservice/6977/4 "2023-10-10T13:12:40Z")

</div>

PS: le cas ci-dessus pourra donc aussi s’implémenter comme suit mais ça n’a pas d’intérêt dans un cas comme ça:

```java
	@Override
	public Object actionService(Action action) {
		if ("TestAction".equals(action.getName())) {
			ObjectField p = action.getConfirmField(getGrant().getLang(), "testParam");
			return Message.formatSimpleText("Hello " + p.getValue() + " world!");
		} else
			return null;
	}

```

---

<div class="post-metadata">

**Author:** ![system](https://community.simplicite.io/user_avatar/community.simplicite.io/system/32/4700_2.png) [@system](https://community.simplicite.io/u/system)\
**Post date:** [November 9, 2023, 1:12pm UTC](https://community.simplicite.io/t/recuperer-un-parametre-daction-depuis-le-hook-actionservice-dun-objectservice/6977/5 "2023-11-09T13:12:51Z")

</div>

Closed on November 9, 2023, 1:12pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
