Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Scripting mot CO, Document Dialog

This command fails to its job. There is no errormessages or anything, but it doesn't set the right template.  In some cases it sets the proper template (in the dropdown) but the actual template file is not set.

The same bug showed up i 7.*, I reported it and it was fixed (by Konrad, I believe).  Now it is back.

so.CurrentDocument.Template = tpl;


function wf4_AddDocument(templateid, nodeid) {


var so = global_so;




so.context.CurrentPanel = 11;


tpl = so.GetListItem(130, templateid);

so.CurrentDocument.Template = tpl;




RE: Scripting mot CO, Document Dialog

I need more info about your context & version.
This works for me in my latetst 8.1:


Set app = CreateObject( "SuperOffice.Application" )
If Not app Is Nothing Then
    Set doc = app.CurrentDocument
    Set db = app.Database
    WScript.Echo doc.Header
    WScript.Echo doc.Template.Text

    WScript.Echo doc.Template.T­ext
    app.Context.CurrentPanel = 11
    doc.Template = db.GetListItem(130, 6)
    WScript.Echo doc.Template.Text
    doc.Header = "Set DocTmp test for Inge Simon Thorbjørnsen..."
    WScript.Echo "Error getting application object"
End If


After I save the doc dlg, the record shows correct doc tmp.
This is run as an external script.


Af: Conrad Weyns 25. mar 2017

RE: Scripting mot CO, Document Dialog

I just installed 8.1 RC2 and I am sorry to say, the problem is still there.

Your VBS-example works fine, but my JS-code does not.   It's sort of urgent now, any suggestions ? Workaround, patch whatever....

var so = window.external;
var db = so.Database;
var doc = so.CurrentDocument;

if (contactid>0) {

if (personid>0) {

if (projectid>0) {

so.context.CurrentPanel = 11;

doc.Header = txt;

var tpl = so.Database.GetListItem(130, tplid);

doc.Template = tpl;


Af: Inge Simon Thorbjørnsen 21. sep 2017

RE: Scripting mot CO, Document Dialog

Hi Inge Simon,

Works just fine... Wondering if your mixed javascript casing is causing problems. If you want to do that, might I suggest you use vbscript?

New Document


Here is the HTML/Javascript I used:

<!DOCTYPE html>

    <title>Sample application for SuperOffice CRM Interaction</title>

    <button id="btnOne">Open New Document Dialog</button>

    <script type="text/javascript">

        function clickNewDocument(ev) {
            var so = window.external;
            if(so != null)

                var db = so.Database;
                var doc = so.CurrentDocument;

                if(doc != null)
                    alert(doc.Header + ".");
                    alert(doc.Template.Id + ".");
                    var tempId = doc.Template.Id;

                    so.context.CurrentPanel = 11;
                    doc.Header = "Set From JavaScript";
                    var tpl = so.Database.GetListItem(130, tempId);
                    doc.Template = tpl;
        window.onload = function() {
            document.getElementById("btnOne").onclick = clickNewDocument; 


Best regards.

Af: Tony Yates 22. sep 2017