Field Inheritance
Mechanism for creating documents by inheritance from a source document.
Overview
Field inheritance is a mechanism that allows you to automatically create a new document (target document) from an existing document (source document) by copying all or part of its fields. This feature is particularly useful for:
- Creating linked documents (e.g., Complaint → Corrective Action)
- Duplicating documents with modifications
- Generating child documents in a workflow
- Initializing forms from existing data
The system automatically generates C# code that performs the mapping between source and target fields.
Operating Principle
Inheritance Process
- Form Selection: Choose the source form and target form
- Field Mapping: Mapping between fields of both forms
- Code Generation: Automatic creation of C# inheritance code
- Customization: Adding additional business logic if necessary
- Integration: Calling the inheritance code from a button or workflow action
Architecture
Source Document (Form A)
↓
Inheritance Code (.ascx)
↓
Target Document (Form B)
Configuration in Process Studio
Accessing the Field Inheritance Menu
- Open Process Studio
- Menu Forms → Field Inheritance
- The configuration interface displays
Creating a Mapping
Step 1: Form Selection
public partial class InheritanceNamePanel : XtraUserControl
{
public InheritanceNamePanel(KeyPair[] forms)
{
InitializeComponent();
lookUpEditSourceForm.Properties.DataSource = forms;
lookUpEditTargetForm.Properties.DataSource = forms.Clone();
}
}
Interface:
- Source form: Form from which to copy data
- Target form: Form to create with inherited data
Step 2: Field Mapping
For each field to inherit:
- Select a source field (left column)
- Select a target field (right column)
- Click the button to add the mapping
- A line of code is automatically generated
Mapping Example:
Source Form: Fiche_SMS
- Titre → Titre (Fiche_Action)
- Description → Descriptif (Fiche_Action)
- DateCreation → DateOuverture (Fiche_Action)
Step 3: Inheritance Parameters
public class InheritanceParams
{
public string IdFormularSource { get; set; }
public string IdFormularTarget { get; set; }
public string AscxFileName
{
get { return string.Format("{0}{1}.ascx", IdFormularSource, IdFormularTarget); }
}
}
The generated file will be named: FormSource_FormCible.ascx
Generated Code
ASCX File Structure
The system generates an .ascx file containing the RunInheritanceFields method:
<%@ Control Language="C#" ClassName="Formulaire_Source____Formulaire_Cible" %>
<script runat="server">
public void RunInheritanceFields(
Avanteam.Documents.Interface.IApsDocument docSource,
Avanteam.Documents.Interface.IApsDocument docTarget)
{
//START_CODE_INHERITANCE
// Automatically generated field mappings
docTarget.SetValues("Titre", docSource.GetValues("Titre"));
docTarget.SetValues("Description", docSource.GetValues("Description"));
docTarget.SetValues("DateOuverture", docSource.GetValues("DateCreation"));
//END_CODE_INHERITANCE
}
</script>
File Location
Generated files are stored in:
Forms/InheritanceFields/
Field Copy Syntax
Simple Copy
// Direct field copy
docTarget.SetValues("NomChampCible", docSource.GetValues("NomChampSource"));
Copy with Transformation
// Copy with formatting
docTarget.SetValues("Title", docSource.GetStringValue("Title", "{0} (Héritage)"));
Multiple Values
// Copy multi-valued fields
docTarget.SetValues("Responsables", docSource.GetValues("Responsables"));
Code Customization
Adding Business Logic
The generated code can be manually completed between the tags:
//START_CODE_INHERITANCE
// Automatically generated code
docTarget.SetValues("Titre", docSource.GetValues("Titre"));
// === Manually added custom code ===
// Parent-child link
docTarget.SetValues("ParentId", docSource.IdDocument);
docTarget.SetValues("ParentReference", docSource.GetValues("Reference"));
// Calculations
docTarget.SetValues("DateEcheance", DateTime.Now.AddDays(30));
//END_CODE_INHERITANCE
Automatic Workflow Launch
// Save the target document
((Avanteam.Documents.DocumentDocHelper)docTarget).SaveDocument();
// Start the workflow
new Avanteam.Application.WorkflowClientRuntime(
new Avanteam.Application.DataSource.ApplicationDataSource
{
UserName = Avanteam.Application.Security.APSUser.GetUserFromSession().FullName,
CurrentIdDocument = docTarget.IdDocument
})
.StartProcessByName("NOM_DU_WORKFLOW");
// Redirect to the new document
Page.Response.Redirect(
Page.ResolveUrl("~/PageLoader.ashx?Edit&IdDoc=" + docTarget.IdDocument),
true);
Copying Detail Tables
Avanteam.Documents.DataSource.DocumentManagerWrapper docMng =
((Avanteam.Documents.DocumentDocHelper)docSource).DocumentDataSource;
if (docMng != null)
{
// Copy rows from a detail table
string sqlInsertDetails = @"
INSERT INTO TableauDetails
SELECT
NEWID() as id,
@IdNewDoc as id_document,
Colonne1, Colonne2, Colonne3
FROM TableauDetails
WHERE id_document = @IdDoc";
docMng.SQL_ExecuteNonQuery(
sqlInsertDetails,
new Avanteam.Kernel.KeyPair("IdDoc", docSource.IdDocument),
new Avanteam.Kernel.KeyPair("IdNewDoc", docTarget.IdDocument));
}
Retrieving the Connected User
Avanteam.Application.DataSource.ApplicationDataSource dataSource =
parameters["ApplicationDataSource"] as Avanteam.Application.DataSource.ApplicationDataSource;
string currentUser = dataSource.UserName;
// Assign the user to a field
docTarget.SetValues("Demandeur", currentUser);
Integration in the Application
Creating the Button Component
Create a custom component to call the inheritance:
File: CreateDocumentFromInheritance.ascx.cs
using System;
using System.Web.UI;
using Avanteam.Documents;
using Avanteam.Documents.Interface;
public partial class CreateDocumentFromInheritance : UserControl
{
protected void btnCreateAction_Click(object sender, EventArgs e)
{
// Retrieve the source document
IApsDocument docSource = GetCurrentDocument();
// Create the target document
IApsDocument docTarget = CreateNewDocument("NomFormulaireCible");
// Load and execute the inheritance code
var inheritanceControl = LoadControl("~/Forms/InheritanceFields/Source_Cible.ascx");
// Call the inheritance method
var method = inheritanceControl.GetType().GetMethod("RunInheritanceFields");
method.Invoke(inheritanceControl, new object[] { docSource, docTarget });
// Redirect to the new document
Response.Redirect("PageLoader.ashx?Edit&IdDoc=" + docTarget.IdDocument);
}
}
File: CreateDocumentFromInheritance.ascx
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="CreateDocumentFromInheritance.ascx.cs"
Inherits="CreateDocumentFromInheritance" %>
<asp:Button ID="btnCreateAction" runat="server"
Text="Créer une action corrective"
OnClick="btnCreateAction_Click"
CssClass="btn btn-primary" />
Adding to FormularDesigner.xml
Reference the component in the configuration:
<Components>
<Component name="CreateAction"
path="~/Custom_Client/CreateDocumentFromInheritance.ascx"
description="Bouton de création par héritage" />
</Components>
Best Practices
Design
- Analyze requirements: Identify fields to copy and necessary transformations
- Name explicitly: Use clear file names (e.g., Reclamation_Action.ascx)
- Document the code: Add comments to explain business logic
- Test before deployment: Verify on test data
Data Management
- Validate source data: Verify that source fields exist and have values
- Handle null values: Provide default values
- Transform if necessary: Adapt formats (dates, numbers, etc.)
- Create links: Reference the source document (ParentId)
Performance
- Limit SQL queries: Group operations
- Optimize table copies: Use efficient SQL queries
- Copy only what's necessary: Avoid copying all fields
Maintenance
- Version the code: Keep inheritance versions
- Test after modifications: Verify impact on forms
- Manage incompatibilities: Plan for handling structure changes
References
Main Classes
InheritanceParams: Inheritance configuration parametersInheritanceNamePanel: Form selection interfaceIApsDocument: Source and target document interfaceDocumentDocHelper: Helper for document manipulation
Files and Directories
Forms/InheritanceFields/: Generated inheritance filesCustom_Client/: Custom componentsFormularDesigner.xml: Component configuration