Publication XML syntaxe des boucles

Bonjour,

J’ai besoin de vos lumières…

Je tente de faire une publication XML d’une entité qui peut contenir plusieurs mandats et un mandat contient le nom d’un représentant.
L’idée est donc d’avoir quelques champs de l’entité puis de parcourir les mandats liés et de ramener quelques champs de chaque mandat.

Je m’inspire du training, mais je bute… je récupère les champs Entité et une partie des champs Mandat, mais je n’arrive pas à ramener le nom, le prénom et la fonction du représentant (qui vient de l’objet représentant)…j’ai essayé plein de syntaxe, mais rien qui ne fonctionne.

mon code :

[BEGIN]
<entite>
<raison_sociale>[VALUE:ParticipationEntiteRaison]</raison_sociale>
<service_suivi>[VALUE:participationServiceLibelle]</service_suivi>
<pers_morale_type>[VALUE:ParticipationEntiteTypePers]</pers_morale_type>
<siege_adrs>[VALUE:ParticipationEntiteAdresse]</siege_adrs>
<siege_adrs_no>[VALUE:participationEntiteAdresseNumero]</siege_adrs_no>	
<siege_npa>[VALUE:participationEntiteAdresseCp]</siege_npa>
<siege_commune>[VALUE:participationEntiteAdressCommune]</siege_commune>
<mandat>
	[BEGIN:ParticipationMandat:ParticipationMandat_ParticipationEntite_fk]
	<nomRepresentant>ParticipationMandat_ParticipationRepresentant_fk.participationReprNom</nomRepresentant>
	<prenomRepresentant>ParticipationMandat_ParticipationRepresentant_fk.participationReprPrenom</prenomRepresentant>
	<fonctionVille>ParticipationMandat_ParticipationRepresentant_fk.participationReprFonction</fonctionVille>
	<fonctionMandat>[participationMandatFonction]</fonctionMandat>
	<mandatArchive>participationMandatArchive</mandatArchive>
	[END:ParticipationMandat]	
</mandat>
</entite>

[END]

et le résultat

Andouille que je suis… j’oubliais les [ ] pour mes champs… du coup c’est OK sauf pour un :

La rubrique “fonction” (fonction ville) qui se trouve dans le REPRÉSENTANT et qui vient de FONCTION…

Quelle syntaxe pour récupérer un champ qui provient d’une table lié à une table?

Dans mon cas, depuis ENTITE, je cherche à obtenir la rubrique “fonction” qui se trouve dans REPRESENTANT avec MANDAT entre 2…

J’ai testé par exemple :

[BEGIN]
<entite>
<raison_sociale>[VALUE:ParticipationEntiteRaison]</raison_sociale>
<service_suivi>[VALUE:participationServiceLibelle]</service_suivi>
<pers_morale_type>[VALUE:ParticipationEntiteTypePers]</pers_morale_type>
<siege_adrs>[VALUE:ParticipationEntiteAdresse]</siege_adrs>
<siege_adrs_no>[VALUE:participationEntiteAdresseNumero]</siege_adrs_no>	
<siege_npa>[VALUE:participationEntiteAdresseCp]</siege_npa>
<siege_commune>[VALUE:participationEntiteAdressCommune]</siege_commune>
<mandat>
	[BEGIN:ParticipationMandat:ParticipationMandat_ParticipationEntite_fk]
	<nomRepresentant>[ParticipationMandat_ParticipationRepresentant_fk.participationReprNom]</nomRepresentant>
	<prenomRepresentant>[ParticipationMandat_ParticipationRepresentant_fk.participationReprPrenom]</prenomRepresentant>
	<fonctionVille>Fonction ville : [ParticipationRepresentant:ParticipationRepresentant_ParticipationFonction_fk.participationFonctionNom]</fonctionVille>
	<fonctionMandat>Fonction pour le mandat : [participationMandatFonction]</fonctionMandat>
	<mandatArchive>[participationMandatArchive]</mandatArchive>
	[END:ParticipationMandat]	
</mandat>
</entite>

[END]

je me compliquais la vie… j’ai trouvé quelque chose qui fonctionne (je fais les questions-réponses tout seul :-) ) :

<fonctionVille>Fonction ville : [ParticipationRepresentant_ParticipationFonction_fk.participationFonctionNom]</fonctionVille>

par contre je me demande s’il est possible de limiter le nombre d’éléments à remonter :
par exemple une entité peut avoir 10 mandats, mais je souhaiterais récupérer seulement les 5 derniers… c’est possible ça ?

Non en l’état ce n’est pas possible de limiter le nombre de records au niveau du template de publication. Il faut mettre en place cette règle dans le code de l’objet en détectant qu’on est dans le contexte d’une publication.

PS: Attention la syntaxe pour les attributs c’est [VALUE:monAttribut], la syntaxe sans le VALUE: est deprecated

Bonjour David,
Merci pour le rappel [VALUE:monAttribut], j’ai corrigé.

Je ne suis pas sûr de bien comprendre où et comment je détecte le contexte de publication. Aurais-tu évt. un exemple sous le coude?

Il faut se servir du contexte d’utilisation de l’objet, ex:

@Override
public void preSearch() {
	if (getContext().isPrintTemplate()) {
		AppLog.info("Print template context  " + getContext().printtmplName, getGrant());
		// Do something for publication
	} else {
		// Undo what you have done for publication
	}
}

cf. https://docs.simplicite.io/4.0/javadoc/com/simplicite/util/ObjectCore.html#getContext()
et https://docs.simplicite.io/4.0/javadoc/com/simplicite/util/ObjectContext.html