Tablescripts Insert/Update - can you make javascript API calls from them? (Sage CRM 2018 R2)

SOLVED

Is this possible at all  ?  I have tried using $.ajax (which im assuming is not available as its serverside) , the XMLHttpRequest() object, and the fetch() function and none of them appear to work for me.When a particular field value changes I want to call a 3rd party JSON API.

Any pointers or should I try and stick to doing it clientside (which I could do but I will have to remember all the screens where this field value could change in)?

Thanks in advance

Chris

  • +1
    verified answer

    Yes you could use the MSXML2 object (usually its installed on the server)

    here is a get and post example functions showing how it could be used.


    function geturl(value) {
        var xmlhttp;
        try {
            xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.4.0");
            }
            catch (e) {
                throw "object can't created";
            }
        }
        xmlhttp.open("GET", value, false);
        xmlhttp.send();
        return (xmlhttp.responseText);
    }
    function posturl(url, postdata) {
        //postdata is name=value&name2=value2 etc
        var xmlhttp;
        try {
            xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.4.0");
            }
            catch (e) {
                throw "object MSXML2.ServerXMLHTTP cannot be created";
            }
        }
        xmlhttp.open("POST", url, false);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.send(postdata);
        return (xmlhttp.responseText);
    }

  • 0 in reply to CRMTogether

    Thanks that works a treat!