Create document order sample - zentry-developer/sdk GitHub Wiki
In this sample, we are creating a document order for an order definition which requires a student to sign the document. Since the student is not of legal age to sign, we include the legal guardians of the student.
// Fetch the list of document order definitions from the definitions facade.
var definitions = await _definitionsFacade.ListDocumentOrderDefinitions();
// Find the specific document order definition by name.
var definition = definitions.First(d => d.Name == "Skolekontrakt");
// Generate random IDs for the child and parents.
var childId = RandomId();
var parent1Id = RandomId();
var parent2Id = RandomId();
// Groups are optional. A group is used as a visual aid for the users of Zentry to group contacts.
var group = new Group(RandomId())
{
Name = RandomName() // Assign a random name to the group.
};
// Create a list of contacts, including the child and their guardians.
var contacts = new List<ContactRef>
{
new Contact(childId, RandomName()) // Create a contact for the child.
{
NationalId = RandomNationalId(), // Assign a random national ID.
SignerRoles = new List<string> { "student" }, // Specify the role of the contact.
Group = group // Assign the contact to the defined group.
},
new Contact(parent1Id, RandomName()) // Create a contact for the first parent.
{
Email = $"{parent1Id}@zentry.dk", // Assign an email based on the parent's ID.
},
new Contact(parent2Id, RandomName()) // Create a contact for the second parent.
{
Email = $"{parent2Id}@zentry.dk", // Assign an email based on the parent's ID.
}
};
// Create relationships between the parents and the child, specifying their roles.
var relations = new List<ContactRelation>
{
new ContactRelation(parent1Id, childId, new List<string> { "legal-guardian" }), // Relation for the first parent.
new ContactRelation(parent2Id, childId, new List<string> { "legal-guardian" }) // Relation for the second parent.
};
// Define the subjects for the document order, which include the child's contact details.
var subjects = new List<Subject> { new("contact", childId) };
// Create merge fields to include dynamic content in the document.
var mergeFields = new List<KeyValueField>
{
new KeyValueField("elevnavn", "Jens"), // Student's first name.
new KeyValueField("elevefternavn", "Jensen"), // Student's last name.
new KeyValueField("elevadresse", "Paradisæblevej 8, 8000 Aarhus"), // Student's address.
new KeyValueField("elevnummer", "8888"), // Student's number.
new KeyValueField("klassetrin", "9") // Student's grade level.
};
// Create a document order request and send it to the orders facade for processing.
await _ordersFacade.CreateDocumentOrders(new List<DocumentOrderRequest>
{
new(definition.Id, subjects, contacts, mergeFields) // Create a new document order request with the provided data.
{
Relationships = relations // Attach the relationships to the document order.
}
});