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!!
17 h, 50 m sedan | 02:00 em
Senaste svar
It looks like you put in the custom variables as Word merge variables. This is not correct, the custom tags that you can provide here are similar to the normal SuperOffice document tags, for office documents (Version > 2007) you should put these in with { }, so for example {VisitDate}, {VisitType}. See docs here: Template variables It is not possible to print multiple rows like the quote details tablestart/tableend with this functionality. Note: Not 100% sure, but I think there is a limitation to these custom tags that the tag name/key can only be 4 characters (so for example {vidi}). EDIT: Yes, see documentation ;
13 h, 58 m sedan | 05:51 em