<img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=6889170&amp;fmt=gif">
Skip to content
  • There are no suggestions because the search field is empty.

Overview | Working with Families

Documents in ReadySuite can be organized into families — a parent document with one or more child attachments. This topic covers querying family relationships, building new families, and restructuring existing ones.

Family Basics

A family consists of a parent DocumentItem and its attachments (children). Every document exposes properties and methods for navigating these relationships:

Method / Property Description
HasFamily() Returns true if the document belongs to a family
IsParent() Returns true if the document is a parent (has or can have attachments)
IsRootParent() Returns true if the document is the top-level parent
IsAttach() Returns true if the document is an attachment (child)
HasAttach() Returns true if the document has at least one attachment
Parent Gets or sets the parent document reference
GetAttachments() Returns the list of child documents

Checking Relationships

C# Copy
while (script.ReadDocument())
{
    var document = script.Document;

    if (document.IsParent() && document.HasAttach())
    {
        var attachments = document.GetAttachments();
        script.AddMessage(string.Format("{0} has {1} attachments",
            document.DocId, attachments.Count));
    }
}

Iterating a Family

To process a parent and all its children together:

C# Copy
while (script.ReadDocument())
{
    var document = script.Document;

    if (!document.IsParent())
        continue;

    // Process the parent
    ProcessDocument(document);

    if (document.HasAttach())
    {
        foreach (var child in document.GetAttachments())
        {
            ProcessDocument(child);
        }
    }
}

Adding Attachments

To attach a new document as a child of an existing parent:

C# Copy
var parent = script.Document;
var child = script.GetNewDocument("ATTACH-0001");
child.SetNative(child.GetNewNative(filePath));
script.CreateDocument(child);
parent.AddAttachment(child);
script.UpdateDocument(parent);

AddAttachment() sets the child's Parent property automatically.

Removing Attachments

ClearAttachments() removes all child relationships from a parent:

C# Copy
document.ClearAttachments();
script.UpdateDocument(document);

The forceUpdateParent parameter (default true) controls whether the parent reference is updated immediately.

Reassigning a Parent

You can move a document to a different family by setting its Parent property:

C# Copy
var child = script.Document;
child.Parent = newParent;
script.UpdateDocument(child);

Full Example

This example finds standalone documents (no family) and groups them under a new parent based on a shared key field:

C# Copy
public override void Run(IScriptContext script)
{
    base.Run(script);

    // First pass: group standalone documents by key
    var groups = new Dictionary<string, List<DocumentItem>>();
    var documents = script.GetDocuments();

    foreach (var doc in documents)
    {
        if (doc.HasFamily())
            continue;

        var key = doc.GetFieldData(options.GroupField);
        if (string.IsNullOrEmpty(key))
            continue;

        if (!groups.ContainsKey(key))
            groups[key] = new List<DocumentItem>();

        groups[key].Add(doc);
    }

    // Second pass: create families
    foreach (var group in groups)
    {
        if (group.Value.Count < 2)
            continue;

        var parent = group.Value[0];
        for (int i = 1; i < group.Value.Count; i++)
        {
            parent.AddAttachment(group.Value[i]);
        }
        script.UpdateDocument(parent);
    }
}