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.CurrentDocument.cancelchanges();

so.CurrentDocument.ChangeIdentity(0);

so.CurrentDocument.setdefaults();

so.context.CurrentPanel = 11;

 

tpl = so.GetListItem(130, templateid);

so.CurrentDocument.Template = tpl;

}

 

samme 

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
    
    doc.CancelChanges()
    doc.ChangeIdentity(0)
    doc.Setdefaults()

    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..."
Else
    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.

/Conrad

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) {
so.CurrentContact.ChangeIdentity(contactid);
}

if (personid>0) {
so.CurrentPerson.ChangeIdentity(personid);
}

if (projectid>0) {
so.CurrentProject.ChangeIdentity(projectid);
}

doc.cancelchanges();
doc.ChangeIdentity(0);
doc.setdefaults();
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>
<html>

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

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

    <script type="text/javascript">

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

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

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

                    doc.CancelChanges();
                    doc.ChangeIdentity(0);
                    doc.SetDefaults();
                    
                    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; 
        };
    </script>
</body>

</html>

Best regards.

Af: Tony Yates 22. sep 2017