push_pin
lock
CreateNewPhysicalDocumentFromTemplateWithCustomTags - How does it work
I'm having trouble understanding how this method in the NSDocumentAgent class works. I have a customer who, before all visits with their customers, need to get a word-document generated with all visits they made in the last year. I have tried fixing this with a document template. But, I can't get the tags to fill into the document. in the document, I have used mergefields to create the tags, which are identical to my code, but it's not working currently, nothing is filled in. This is what my code looks like. #setLanguageLevel 4; //Agenter NSDocumentAgent documentAgent; NSAssociateAgent aAgent; NSContactAgent cAgent; // Hämta data från eventet EventData ed = getEventData(); //log("ed: " + parseJSON(ed.getInputValues().toJson()).toJSON(2)); String contact_id = ed.getInputValue("ContactEntity.ContactId"); //Skapar dokumentet, ger det rätt Template NSDocumentEntity documentEntity = documentAgent.CreateDefaultDocumentEntity(); NSDocumentTemplate documentTemplate; documentTemplate.SetDocumentTemplateId(179); documentEntity.SetDocumentTemplate(documentTemplate); Date now; NSAssociate ass = aAgent.GetAssociate(3); NSContact contact = cAgent.GetContact(contact_id.toInteger()); // Definiera dokumentet documentEntity.SetName(now.toString() + " - Besöksprotokoll.docx"); documentEntity.SetAssociate(ass); documentEntity.SetContact(contact); documentEntity.SetHeader(now.toString() + " - Besöksprotokoll"); documentEntity.SetDate(getCurrentDateTime()); documentEntity = documentAgent.SaveDocumentEntity(documentEntity); //Hämtar all information SearchEngine se; se.addFields("appointment","activeDate,task_idx.name,agenda_text_id.text,type,text_id.text,associate_id.person_id.firstname,associate_id.person_id.lastname"); se.addCriteria("appointment.contact_id","Equals",contact_id); se.addCriteria("appointment.task_idx","Equals","7"); se.addOrder("appointment.activeDate",true); se.setLimit(1); //print(se.executeHTMLTable()); //String result = ""; String[] customTags; String[] customValue; for(se.execute();!se.eof();se.next()) { String date = se.getField("appointment.activeDate"); customTags.pushBack("VisitDate"); customValue.pushBack(date); String task = se.getField("appointment.task_idx.name"); customTags.pushBack("VisitType"); customValue.pushBack(task); String text = se.getField("appointment.text_id.text"); customTags.pushBack("VisitText"); customValue.pushBack(text); String person = se.getField("appointment.associate_id.person_id.firstname") + " " + se.getField("appointment.associate_id.person_id.lastname"); customTags.pushBack("VisitPerson"); customValue.pushBack(person); ///// } NSDocumentEntity doc = documentAgent.CreateNewPhysicalDocumentFromTemplateWithCustomTags(contact_id.toInteger(),0,0,documentEntity.GetDocumentId(),0,0,0,customTags,customValue,"sv-SE"); Anyone know what I have done wrong? And a separate question, haha, in the end I want to include many rows of this, similarly to how the quote module works. Is this possible? As you can see now, I'm only trying to get one row working as a first step. Thank you in advance!!