How create documents using custom template variables

lock
push_pin
done
Answered
4

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"), "");

3 Oct 2023 | 09:15 AM

All Replies (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.

3 Oct 2023 | 09:41 AM

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

3 Oct 2023 | 09:56 AM
No experience with this requirement! Good luck finding the best solution here :-)
3 Oct 2023 | 10:04 AM

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.

14 Dec 2023 | 01:02 PM

Add reply