Skip to main content
Version: Next

Mise à jour, dans l'historique de workflow, du dernier commentaire saisi

Objectif : Permettre la modification, dans la transition qui suit l'étape, du commentaire saisi lors de la validation de l'étape.

Introduction : La mise en place de l'action de workflow permettant la modification du dernier commentaire de l'historique, nécessite la génération d'une DLL avec le code C# ci-après.

Références requises :

  • Avanteam.Application
  • Avanteam.Documents
  • Avanteam.Kernel
  • Avanteam.Workflow.ComponentModel
  • Avanteam.Workflow.DataSource
  • Avanteam.Workflow.Runtime
  • Microsoft.CSharp
  • System
  • System.Data
  • System.Data.DataSetExtensions
  • System.Xml
  • System.Xml.Linq

Code C# :

using Avanteam.Application;
using Avanteam.Application.DataSource;
using Avanteam.Kernel.Attributes;
using Avanteam.Workflow.DataSource;
using Avanteam.Workflow.Runtime;

using System.Collections;
using System.Linq;

[assembly: ScriptAssembly]
namespace Avanteam.Actions
{
[ScriptClass]
public class Workflow
{
[ScriptMethod]
public bool UpdateLastComment(Hashtable parameters)
{
ApplicationDataSource dataSource = parameters["ApplicationDataSource"] as ApplicationDataSource;
Instance instance = parameters["Instance"] as Instance;

string LastComment = GetLastComment(instance); // Dernier commentaire de workflow saisi

/* DEBUT - CODE PERSONNALISABLE */

string nouveau_commentaire = "Nouveau commentaire : _NOUVEAU_COMMENTAIRE_ || Ancien commentaire : " + LastComment;

/* FIN - CODE PERSONNALISABLE */

UpdateLastComment(dataSource, instance, nouveau_commentaire); //Mise à jour du dernier commentaire de workflow saisi

return true;
}

private void UpdateLastComment(ApplicationDataSource dataSource, Instance instance, string message)
{
//Nettoyage de l'historique de workflow lié à l'action en cours dans les datasets
WorkflowClientRuntime wrt = new WorkflowClientRuntime(dataSource);
WorkflowDataSource _instanceDataSource = wrt.DataSource;
_instanceDataSource.DSWorkflow.ProcessHistory.RemoveProcessHistoryRow(_instanceDataSource.DSWorkflow.ProcessHistory.FindByid(instance.NavigateRootParent.History[0].Id));

instance.NavigateRootParent.History.Clear(); //Nettoyage de l'historique de workflow lié à l'action en cours dans l'instance parente

//Récupération, récursive, de l'activité correspondant à la dernière étape traversée
Instance activity = instance.Previous;
while (activity.Component.ComponentType != Avanteam.Workflow.ComponentModel.WorkflowComponentType.Activity || !activity.Component.Id.Contains("Etape"))
{
activity = activity.Previous;
}

Instance workitem = activity.Childs.FirstOrDefault(o => o.InstanceProperties.Contains("Comment_" + wrt.CurrentPerformer)); //Récupération de la dernière action manuelle, lié à la dernière étape travérsée, dans laquelle l'utilisateur a saisi un commentaire

if (workitem == null) return; //Aucun commentaire n'a été saisi à la dernière étape, ANNULATION de la mise à jour

workitem.InstanceProperties["Comment_" + wrt.CurrentPerformer] = message; //Mise à jour du commentaire saisie par l'utilisateur
workitem.Runtime.InvokeInstance(workitem); //Création d'une nouvelle entrée dans l'historique de workflow avec le nouveau commentaire
}

private string GetLastComment(Instance instance)
{
return instance.NavigateRootParent.InstanceProperties.ContainsKey("LastComment") ?
instance.NavigateRootParent.InstanceProperties["LastComment"].ToString()
: "";
}
}
}