Quantcast
Viewing all articles
Browse latest Browse all 2504

JavaScript API When are the window.external objects available?

Topic by Yorktech

Hi

I'm having some problems with the Connect Desktop Javascript API. I'm running Javascript within a browser control via the agent desktop.
My problem is that when I'm accessing the external objects (i.e window.external.contact / window.external.incident) either on document.ready or window.load they're blank.
If I add a button on the page and add an onlick and then access the incident or contact objects they're accessable. 

So at what stage or the external objects available?  I'd like to be able to access them on window.load or document.ready......

Thanks
Steve.


HTML snippet


    <div class="row">
        <div class="col-md-12">
            <div class="jumbotron">
                <p><strong>Contact Details</strong>
                <p id="contact"></p>
                <p>
                    <strong>Incident Details</strong>
                </p>
                <p id="incident"></p>
                <p>
                    <strong>Location Object</strong>
                </p>
                <p id="location"></p>
            </div>
            <form>
               
                <textarea class="form-control" id="text" name='ta' cols=40 rows=8></textarea>

                <a class="btn btn-info" onclick='populate()'>Check Data</a>
            </form>
    
        </div>
    </div>


Javascript 

This doesn't work........

$(window).load(function () {
        alert("hello the browser window is now fully loaded all data should be available??????");
        var contact = window.external.Contact;
        var incident = window.external.Incident;
        var json = JSON.stringify(window.external);
        if (contact != null ) {
            alert("contact is not null, so should contain data.......");
            var msg = "Name: " + contact.FullName + "Email: " + contact.EmailAddr + "ID: " + contact.Id;
            $("#contact").html("Contact data" + msg);
            alert(msg);
        } else {
            $("#contact").html("No data in the contact object");
        }
        if (incident != null) {
            var idata = objToString(incident);
            $("#incident").html("Incident is not null data is....: " + idata + json);
        } else {
            $("#incident").html("No data in the incident object");
        }
      
      
    });


This does.......

function populate() {

    var c = window.external.Contact;
    var incident = window.external.Incident;

    var msg = "blank contact";
    try {
        if (c != null) {
            msg = "Name: " + c.FullName + "\nEmail: " + c.EmailAddr + "\nc_id: " + c.Id;
        }
    }
    catch (err) {
        msg = "There was an error accessing the contact object, it may be blank! ";
    }

    var data = "blank incident";
    try {
        if (incident != null) {
            data = "ID:" + incident.ID + "Queue Id " + incident.QueueId + " Subject " + incident.Subject + "Disposition" + incident.Disposition;

        }

    } catch (err) {
        data = "There was an error accessing the incident object, it may be blank! ";
    }
    $("#text").val( msg + "" + data);
}


Viewing all articles
Browse latest Browse all 2504

Trending Articles