Skip to main content
Version: Next

Affichage par défaut de l'utilisateur courant / son service / son chef de service / de l'utilisateur ayant le rôle XXX / la date du jour

Cette fonction est utile pour le paramétrage d'un champ afin de faire apparaître le service et chef de service de l'utilisateur connecté :

Dans options avancées du champ, mettre dans 'DefaultValue' :

Récupération du user courant :

Pour obtenir le dn_name :

returnValue = apsSession["UserFullName"].ToString();

ou

returnValue=string.Format("{0}",apsSession["UserFullName"]);

Pour obtenir le cn_name :

returnValue = apsSession["UserName"].ToString();

ou

returnValue=string.Format("{0}",apsSession["UserName"]);

Récupération du service du user courant :

Avanteam.Application.Security.APSUser p_user = new Avanteam.Application.Security.APSUser(apsSession["UserFullName"].ToString());
returnValue = "-";
if(p_user.Services.Count > 0)
returnValue = p_user.Services[0];

Ou plus simple :

returnValue = (new Avanteam.Application.Security.APSUser((string)apsSession["UserFullName"])).Services[0];

Récupération du service du user inscrit dans un champ :

var utilisateur = doc.GetStringValue("Approbateur");
var apsUser = new Avanteam.Application.Security.APSUser( utilisateur );
var service = apsUser.Services[0];
returnValue= service;

Récupération du dn_name du Manager du service du user courant :

Avanteam.Application.Security.APSUser p_user = new Avanteam.Application.Security.APSUser(apsSession["UserFullName"].ToString());
returnValue = "-";
if(p_user.Services.Count > 0)
{
string serv= p_user.Services[0];
if( p_user.DirectoryDataSource.GetServiceLeaders(serv).Count > 0)
returnValue = ((System.Collections.Generic.List<string>)p_user.DirectoryDataSource.GetServiceLeaders(serv))[0];
}

Récupération de la personne (ou des personnes) possédant un rôle particulier :

Avanteam.Directory.DataSource.DirectoryManagerWrapper d = new Avanteam.Directory.DataSource.DirectoryManagerWrapper();
string role = "NOM DU ROLE";
string[] personnes = d.GetPersonsInRole(role);
returnValue = string.Join(";",personnes.ToArray());

Récupération de la date du jour :

returnValue=System.DateTime.Now.ToString();