How to create a new document in SO_ARC
Audience:
•
Version: 10
Some tooltip text!
• 3 minutes to read
• 3 minutes to read
To create a new document, create a document
entity and set the document properties. In this example, we have used a specific document template on which the document is based. The owner of the document is set, followed by the associated person and project with which the document is connected.
public int CreateDocument()
{
// create a document entity
DocumentEntity documentEntity = new DocumentEntity();
// set properties of document entity
documentEntity.Attention = "Thomas O S";
documentEntity.Header = "Test document";
documentEntity.Name = "Test.doc";
documentEntity.OurRef = "Our Reference";
documentEntity.YourRef = "Your Reference";
documentEntity.Description = "This is a new document entity created using IDocument Agent";
documentEntity.Date = DateTime.Today;
documentEntity.ExternalRef = "External Reference";
// set the document template for the document
DocumentTemplate docTmpl = new DocumentTemplate();
docTmpl.DocumentTemplateId = 1;
documentEntity.DocumentTemplate = docTmpl;
// set the owner of the document
Associate owner = new Associate();
owner.AssociateId = 110;
documentEntity.Associate = owner;
// set the person to whom the document is connected : optional
Person person = new Person();
person.PersonId = 12;
documentEntity.Person = person;
// set the contact associated with the document: can also be null
Contact contact = new Contact();
contact.ContactId = 4;
documentEntity.Contact = contact;
// set the project to which the document is connected : optional
Project project = new Project();
project.ProjectId = 15;
documentEntity.Project = project;
//create new instance
using(DocumentAgent agent = new DocumentAgent())
{
DocumentEntity createdDocumentEntity = agent.SaveDocumentEntity(documentEntity);
// create a new physical document and store it in the document archive
agent.CreateNewPhysicalDocumentFromTemplate(
createdDocumentEntity.Contact.ContactId,
createdDocumentEntity.Person.PersonId,
0,
createdDocumentEntity.DocumentId,
0,
0,
createdDocumentEntity.Project.ProjectId);
return createdDocumentEntity.DocumentId;
}
}
Once the property values are set, the document is persisted to the database using the DocumentAgent.SaveDocumentEntity
method. This call creates a new Document
record in the database and returns a DocumentEntity
instance that now contains a document ID.
With a Document
record in the database, you create the physical document and save it in the document archive. Do this using the DocumentAgent.CreateNewPhysicalDocumentFromTemplate
method. Required input:
- contact
- person
- appointment
- sale
- selection
- project IDs
- the document ID