Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Create document with custom tags and values (CRMScript)

How does this 'CreateNewPhysicalDocumentFromTemplateWithCustomTags' function work? I can't get this working well...
The document is created, but no custom values are filled in the document.

NSDocumentTemplate docTempl;
docTempl.SetDocumentTemplateId(docTemplateId);

NSDocumentAgent docAgent;
NSDocumentEntity document = docAgent.CreateDefaultDocumentEntity();

document.SetDocumentTemplate(docTempl);
document.SetName(unixDate + ".xls");
document.SetHeader("NieuwDocument_" + unixDate);
document.SetDate(now);

NSAssociate associate;
if (associateId > 0) {
  associate.SetAssociateId(associateId);
  document.SetAssociate(associate);
}

NSContact contact;
if (contactId > 0) {
  contact.SetContactId(contactId);
  document.SetContact(contact);
}

String[] arrayTags;
arrayTags.pushBack("<test>");
arrayTags.pushBack("<k1>");
arrayTags.pushBack("<k2>");

String[] arrayValues;
arrayValues.pushBack("TestValue");
arrayValues.pushBack("20");
arrayValues.pushBack("5");

document = docAgent.SaveDocumentEntity(document);
docAgent.CreateNewPhysicalDocumentFromTemplateWithCustomTags(contactId, 0, 0, document.GetDocumentId(), 0, 0, 0, arrayTags, arrayValues, "nl-NL");

RE: Create document with custom tags and values (CRMScript)

Hi Brian,

Try using the 'CreateNewPhysicalDocumentFromTemplateWithCustomTags2' method, then you can use a Map for the tags.

Also you don't need to specify the template variable start and end marker, that is determined by the file extension.

 

#setLanguageLevel 3;

Integer docTemplateId = 0;
Integer associateId = 0;
Integer contactId = 0;


String unixDate = getCurrentDateTime().getUnix().toString();

NSDocumentTemplate docTempl;
docTempl.SetDocumentTemplateId(docTemplateId);

NSDocumentAgent docAgent;
NSDocumentEntity document = docAgent.CreateDefaultDocumentEntity();

document.SetDocumentTemplate(docTempl);
document.SetName(unixDate + ".xls");
document.SetHeader("NieuwDocument_" + unixDate);
document.SetDate(getCurrentDateTime());

NSAssociate associate;
if (associateId > 0) {
  associate.SetAssociateId(associateId);
  document.SetAssociate(associate);
}

NSContact contact;
if (contactId > 0) {
  contact.SetContactId(contactId);
  document.SetContact(contact);
}

// template variable start and end marker are determined by file extension of document, so for .xls use < >, but xlsx use {}, in the actual document
Map customTags;
customTags.insert("test", "TestValue");
customTags.insert("k1", "20");
customTags.insert("k2", "5");


document = docAgent.SaveDocumentEntity(document);
docAgent.CreateNewPhysicalDocumentFromTemplateWithCustomTags2(contactId, 0, 0, document.GetDocumentId(), 0, 0, 0, customTags, "nl-NL");
Af: David Hollegien 13. jul 2021

RE: Create document with custom tags and values (CRMScript)

Thanks David! It works :)

Af: Brian Mulder 13. jul 2021