How is document template language versions handled in DB, and how to set using crmscript?

lock
push_pin
done
Besvarat
12

Hi all.

Just wondering - how is language versions handled for Document templates?

When addin a new language-version I cant see any changes in the DocTmpl-table. Looking the DocTmpl-table up, I can't find anything language-ish mentioned, and haven't had any luck finding any tables where this many-to-many relation would be stored.

Furthermore, how do you create a document in crmscript with a specific language?

When I lookup NSDocumentTemplatei I don't see any language-related attributes. 

 

21. juni 2024 | 10:14 fm

Allt Svar (12)

Document template languages aren't stored in the database anywhere, they are determined based on the subfolders in the SO_ARC template archive folder.

 

24. juni 2024 | 08:27 fm
Okay, so I guess there is no access to set this using crmscript then?
24. juni 2024 | 08:57 fm
You can access the document template related functionality using the NSDocumentAgent and NSListAgent classes. So you should be able to get the information you need from there.
24. juni 2024 | 10:23 fm
How? I cant find any functionality in the NSDocumentAgent class that allows me to generate a document from the eg. German version of a reply template. The only way I know, is to use the DocTmpl-ID, and this always defaults to the default language version (at least what I have figured).
24. juni 2024 | 10:39 fm

Ah yes, when generating a document you can pass the uiCulture to the CreateNewPhysicalDocumentFromTemplate method(s), but that seems to be ignored when generating a document from CRMScript. I guess/assume that the uiCulture also is used when determing which template language variant is used.

See bug registration: https://community.superoffice.com/en/product-releases/bugs-wishes/product-issue/?bid=37238&azure=1

24. juni 2024 | 11:10 fm
I'm not able to reproduce this bug. I think it's just the locale is not specified correctly.

Assuming the document template has both an English and Netherlands language template, this works as expected:

#setLanguageLevel 4;

NSListAgent listAgent;
NSDocumentAgent documentAgent;

Integer documentTemplateId = 52;
Integer contactId = 7179;
Integer personId = 74361;
String language = "en";

NSDocumentEntity documentEntity = documentAgent.CreateDefaultDocumentEntity();

// Set the company
NSContact contact;
contact.SetContactId(contactId);
documentEntity.SetContact(contact);

// Set the contact
NSPerson person;
person.SetPersonId(personId);
documentEntity.SetPerson(person);

// Set the template
NSDocumentTemplate documentTemplate;
documentTemplate.SetDocumentTemplateId(documentTemplateId);
documentEntity.SetDocumentTemplate(documentTemplate);

// Set the name, header and date
documentEntity.SetName("sample_test_culture_bug6-" + getCurrentDateTime().toString("YY4MM2DD2_HH24MI2SS2") + ".docx");
documentEntity.SetHeader("sample_test_culture_bug6-" + getCurrentDateTime().toString());
documentEntity.SetDate(getCurrentDateTime());

// Save the document record into the database
documentEntity = documentAgent.SaveDocumentEntity(documentEntity);

// Generate the physical document.
Map customTags;
documentAgent.CreateNewPhysicalDocumentFromTemplateWithCustomTags2(contactId, 0, 0, documentEntity.GetDocumentId(), 0, 0, 0, customTags, language);
11. juli 2024 | 12:40 em
Just tested this in SOD, it does indeed take the correct document template variant, so that works correctly. The bug i pointed to does still exists, the template variables aren't parsed/formatted according to the given culture.
11. juli 2024 | 01:01 em

To make things more spicy, I'm searching for a way to generate the pdf generated from a quote.

In the GUI (when pressing Send from a quote-draft) ,it is possible to choose which language version you want to use. The quote-documents behind the pdf that is generated is stored in the Document Template table. I guess your method of using NSDocumentAgent.GenerateNewPhysicalDocumentFromTemplate(..) isn't the correct one in this example.

NSQuoteAgent.SendQuoteVersion(...) takes 'culture : String' as an input. But havent figured how this works yet. 

24. juni 2024 | 11:37 fm

In regards to the OP, the document templates must have multiple languages defined in the document template dialog. 

Read the docs to learn how to add languages to a template.

In a CRMScript, assuming the document template Id is 4, if you run the following script do you get the same results?

NSListAgent la;
String[] languages = la.GetDocumentTemplateLanguages(4);

printLine(languages.buildString(","));

Results:

da,nl,en

 

27. juni 2024 | 07:44 fm
Hi Tony.

I know how to add language-versions to templates manually through the user interface.
I'm asking specific for how to do this through scripting. In this case crmscript.

I'm not sure how I should utilize the info I get from GetDocumentTemplateLanguages(templId). This gives me info that - in your case - a nl-version exists, but how do I create a nl-version using crmscript?
27. juni 2024 | 09:09 fm

We have an open support request regarding this and will update as soon as we have more info.

11. juli 2024 | 09:17 fm

To answer your orginal question Kasper:

Integer documentTemplateId = 207;

// get a stream of your document template variant here, for example purposes we just take the existing NL variant
NSStream documentTemplateVariantContent = listAgent.GetDocumentTemplateStreamFromId(documentTemplateId, "nl");

// retrieve existing base document template entity for the plugin code
NSDocumentTemplateEntity documentTemplateEntity = listAgent.GetDocumentTemplateEntity(documentTemplateId);

// create new variant which copies the default one
listAgent.CreateDefaultDocumentTemplateLanguage(documentTemplateId, "fr");

// save our variant
listAgent.SaveDocumentTemplateStream(documentTemplateId, variant, "fr", documentTemplateEntity.GetLoadTemplateFromPlugin());
11. juli 2024 | 01:16 em

Lägg till svar