Document properties
Retrieve document info
To view basic info, use NSDocument
NSDocumentAgent docAgent;
NSDocument doc = docAgent.GetDocument(2);
printLine(doc.GetDocumentName());
To view (and possibly update) complex info, use NSDocumentEntity
NSDocumentAgent docAgent;
NSDocumentEntity doc = docAgent.GetDocumentEntity(1);
printLine(doc.GetContact().GetName());
List all documents with SearchEngine
SearchEngine se;
se.addFields("document", "document_id,name,header");
print(se.executeTextTable());
Tip
If you know there's a lot of documents, consider adding a count criteria to limit the results.
NSDocument[] GetDocumentList(Integer[] p0)
Fetches a collection of documents corresponding to a list of IDs.
Integer[] docIDs;
docIDs.pushFront(84);
docIDs.pushFront(86);
docIDs.pushFront(88);
NSDocumentAgent docAgent;
NSDocument[] docList = docAgent.GetDocumentList(docIDs);
for(Integer i = 0; i < docList.length(); i++) {
printLine(docList[i].GetDocumentId().toString());
}
NSDocument[] GetAppointmentDocuments(Integer appointmentId)
Get all documents that are linked to a follow-up.
Integer appointmentId = 4;
NSDocumentAgent docAgent;
NSDocument[] docList = docAgent.GetAppointmentDocuments(appointmentId);
NSDocument[] GetContactDocuments(Integer contactId, DateTime startTime, DateTime endTime, Integer count)
Fetches a limited number of documents within a time range for the given contact.
NSDocumentAgent docAgent;
DateTime start;
DateTime end;
NSDocument[] docList = docAgent.GetContactDocuments(4, start.addMonth(-6), end, 10);
Tip
Set count
to -1 to not restrict the collection of documents retrieved.
Create document entity
NSDocumentEntity CreateDefaultDocumentEntity()
Create and populate with default values:
NSDocumentAgent agent;
NSDocumentEntity doc = agent.CreateDefaultDocumentEntity();
doc.SetHeader("Test document");
doc.SetName("Test.doc");
doc = agent.SaveDocumentEntity(doc);
printLine(doc.GetDocumentId().toString());
Set document properties for people and organizations
You can choose whether to use an agent to get associate, contact, and person objects by their ID or to create the objects and set the ID.
NSDocumentAgent agent;
NSDocumentEntity doc = agent.GetDocumentEntity(2);
NSAssociate owner;
owner.SetAssociateId(13);
doc.SetAssociate(owner);
NSContact c;
c.SetContactId(2);
doc.SetContact(c);
NSPersonAgent personAgent;
NSPerson p = personAgent.GetPerson(5);
doc.SetPerson(p);
doc = agent.SaveDocumentEntity(doc);
Read more about working with persons and organizations.
Link document to a follow-up
NSDocumentAgent agent;
NSDocumentEntity doc = agent.GetDocumentEntity(2);
NSAppointmentAgent appAgent;
NSAppointmentEntity a = appAgent.CreateDefaultAppointmentEntity();
a.SetDescription(doc.GetHeader());
a.SetContact(doc.GetContact());
NSLink link;
link.SetEntityName("document");
link.SetId(doc.GetDocumentId());
NSLink[] links;
links.pushBack(link);
a.SetLinks(links);
appAgent.SaveAppointmentEntity(a);
Suggested documents
Suggested documents are just that - suggested. They're blueprints that can be used to create actual documents, and are commonly used for sales guides and project guides.
Note
Don't confuse suggested documents for document templates.
List available suggestions
SearchEngine se;
se.addFields("SuggestedDocument", "SuggestedDocument_id,name,saleTypeStageLinkId,projectTypeStatusLinkId");
print(se.executeTextTable());
Create document from suggestion
All you need is the ID of the suggested document, and then calling CreateDefaultDocumentEntityFromSuggestion()
will do the magic for you!
NSDocumentAgent agent;
NSDocumentEntity doc = agent.CreateDefaultDocumentEntityFromSuggestion(3);
doc = agent.SaveDocumentEntity(doc);
printLine(doc.GetDocumentId().toString() + "\t" + doc.GetHeader());
Change document properties
Note
The NSDocumentEntity
can't be changed if the document is marked as Completed.
Use GetCompleted()
to check the status. Toggle it to 0 to do your edits and then toggle it back if necessary.
NSDocumentAgent agent;
NSDocumentEntity doc = agent.GetDocumentEntity(2);
if (doc.GetCompleted() == 3) {
doc.SetCompleted(0);
doc = agent.SaveDocumentEntity(doc);
}
Delete document entity
NSDocumentAgent agent;
agent.DeleteDocumentEntity(99);
Reference
Frequently used fields
Field | Description |
---|---|
document_id | ID |
application_id | application this document was made with |
name | filename with extension |
header | visible document name aka title |
our_ref | our reference (internal) |
your_ref | your reference (external) |
appointment_id | points back to owning appointment |
For a complete list of fields, see the database reference.
Tip
Both our_ref
and your_ref
are strings.