How create documents using custom template variables
Hi all. Im trying to create a document with custom variables using the function CreateNewPhysicalDocumentFromTemplateWithCustomTags2.
The document is created fine, but it doesn't merge the custom tags. In picture below variable gptt isn't even removed. But right next to it, name of company is merged fine. Both using same format in word-document.
NSDocumentAgent da;
NSContactAgent ca;
NSPersonAgent pa;
NSDocumentEntity doc = da.CreateDefaultDocumentEntity();
Integer contactId = formSubmitSE.getField("form_submission.person_id.contact_id").toInteger()+0;
if(contactId > 0)
{
NSContact contact = ca.GetContact(contactId);
doc.SetContact(contact);
}
Integer personId = formSubmitSE.getField("form_submission.person_id").toInteger()+0;
NSPerson person = pa.GetPerson(personId);
doc.SetPerson(person);
NSDocumentTemplate template;
template.SetDocumentTemplateId(180);
doc.SetDocumentTemplate(template);
doc = da.SaveDocumentEntity(doc);
doc = da.CreateNewPhysicalDocumentFromTemplateWithCustomTags2(contactId, personId, 0, doc.GetDocumentId(), 0, 0, 0, Map().insert("gptt", "horse"), "");
Alle Antworten (4)
Hi Kasper - I suggest removing the {gptt} part in your template file (using backspace) and retyping it (manually, no "pasting") and save the template - test again.
Code seems fine to me, probably related to an issue in the word-file itself.
Hi Bas.
It worked when I moved the variable a bit around.
Next question - is it possible to set in text into a single variable, that contains multiple lines?
Tried something like this, but it is just inserted as one bulk of text.
Map().insert("gptt", list.build("\r\n"));
d
Hi, I've create a solution before where a created a custom template variable string including a special character.
When document is created I replaced the special character, within the custom template variable result, with a line break using a macro.
Maybe you could implement something like this.