Field Inheritance
Introduction
Field inheritance allows automatic copying of values from a "Parent" document to a "Child" document during its creation. Example: When creating an Invoice from an Order, automatically retrieve the Supplier Name and Order Number.
Principle
Inheritance is based on the relationship between documents (often via a Link or creation in "sub-process").

Configuration
[!WARNING] This feature requires technical setup (C# Script).
The most flexible way to manage inheritance is to use a dedicated C# method (often called RunInheritanceFields) that takes the Source document and Target document as input.
Example 1: Standard Inheritance (Document to Document)
This case covers the majority of needs: creating a document B from a document A (e.g.: A Modification Request from a Procedure).
<%@ Control Language="C#" ClassName="REF_Document_ModificationRequest" %>
<script runat="server">
public void RunInheritanceFields(Avanteam.Documents.Interface.IApsDocument docSource, Avanteam.Documents.Interface.IApsDocument docTarget)
{
// Retrieving Parent data
var parentDoctitle = docSource.GetStringValue("Title");
var parentDocReference = docSource.GetStringValue("Reference");
var parentDocVersion = docSource.GetStringValue("Version");
// Business logic: Manager or Default Creator
var gestionnaire = docSource.GetStringValue("Ged_Gestionnaire");
var authorFullName = docSource.HasField("Ged_Gestionnaire") && !string.IsNullOrEmpty(gestionnaire)
? gestionnaire
: docSource.GetCreator();
// Mapping to Child
docTarget.SetValues("ParentDocId", docSource.IdDocument);
docTarget.SetValues("Title", "DM : " + parentDocReference + "- V" + parentDocVersion + " / " + parentDoctitle);
docTarget.SetValues("ParentDocTitle", parentDoctitle);
docTarget.SetValues("ParentDocReference", parentDocReference);
docTarget.SetValues("ParentDocVersion", parentDocVersion);
docTarget.SetValues("ParentDocAuthor", authorFullName);
}
</script>
Example 2: Specific Case (Creation from a table row)
This specific development allows creating a new form from a row in a table of the source document (e.g.: Breaking down a global order into multiple product sheets).
<script runat="server">
public void RunInheritanceFields(Avanteam.Documents.Interface.IApsDocument docSource, Avanteam.Documents.Interface.IApsDocument docTarget)
{
// Check if the call comes from a table row
if ((string)docSource["HasRowInfo"] == "1")
{
// Simple field copying
docTarget.SetValues("DescriptionAction", docSource["Row_DocDescription"]);
docTarget.SetValues("DateLimite", docSource["Row_DocDate1"]);
// ... (rest of specific code)
// Copying dropdowns (Stored value)
docTarget.SetValues("Responsable", docSource["Row_DocDropDown1"]);
// Transformation and Truncation
var val = docSource["Row_DocDescription"].ToString()
.Replace(System.Environment.NewLine, " ")
.Replace("\r", " ").Replace("\n", " ");
if(val.Length >= 150)
val = val.Substring(0,150) + "...";
docTarget.SetValues("Title", val);
// Info feedback to source (optional)
docSource["RunProcess"] = "Action";
}
// Systematic Inheritance (Executed in all cases)
docTarget.SetValues("Aps_Societe", docSource.GetStringValue("Aps_Societe"));
docTarget.SetValues("RefPere", docSource.GetStringValue("Reference"));
docTarget.SetValues("ParentDocId", docSource.IdDocument);
}
</script>
Key Explanations
docSource: The existing document (Parent).docTarget: The new document being created (Child).SetValues("FieldName", Value): Method to assign a value in the new form.docSource["FieldName"]: Retrieves the raw value of a source field.IdDocument: It is crucial to store the parent's ID (ParentDocId) if you want to maintain a strong technical link.