javascript to call Navision Web Service..

ForeverBlueForeverBlue Member Posts: 54
edited 2012-02-16 in NAV Three Tier
I have been reading a lot on http://blogs.msdn.com/b/freddyk/ about just javascript to call navision.
i have followed http://blogs.msdn.com/b/freddyk/archive/2010/01/19/connecting-to-nav-web-services-from.aspx by adding <add key="WebServicesUseNTLMAuthentication" value="true"></add> into CustomerSettings.config.

then base on http://blogs.msdn.com/b/freddyk/archive/2010/01/21/connecting-to-nav-web-services-from-javascript.aspx I builded a function just to display the company name but at xmlhttp.open('POST', URL, false);
, I have "Access is denied" error. Does anyone have any idea about this??

Thanks

Comments

  • dipakpatel2505dipakpatel2505 Member Posts: 169
    Hello,

    The use who is accessing Web Service application should be domain user and it should have permission given in Navision.

    Is that User added to NAV and given Persimission ? If Yes and still facing problem then Check whether that User is DBOwner for Database to which User try to access.
  • ForeverBlueForeverBlue Member Posts: 54
    Hi
    I have been test that javascript on the same server as navsion web service and login as administrator so I have all the access right...
  • max_hlmax_hl Member Posts: 13
    Hi
    Try to use this html file to connect to NAV WS (IE confirms security alert to continue if u open it) :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html><head><title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <script type="text/javascript" language="JavaScript">
    var baseURL = 'http://YourServerName:7047/DynamicsNAV/WS/SystemService';

    // Function to Invoke a NAV WebService and return data from a specific Tag in the responseXML
    function InvokeNavWS(URL) {
    var result = null;
    try {
    var xmlhttp;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    var request = '<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">' +
    '<Soap:Body>' + '<Companies xmlns="urn:microsoft-dynamics-schemas/nav/system/"></Companies>' +
    '</Soap:Body></Soap:Envelope>';

    // Use Post and non-async
    xmlhttp.open('POST', URL, false);
    xmlhttp.setRequestHeader('Content-type', 'text/xml; charset=utf-8');
    xmlhttp.setRequestHeader('Content-length', request.length);
    xmlhttp.setRequestHeader('SOAPAction', 'Companies');

    // Setup event handler when readystate changes
    xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4) {
    if (xmlhttp.status == 200) {
    result = xmlhttp.responseXML.text;
    }
    else {
    result = xmlhttp.statusText;
    }
    }
    }
    xmlhttp.send(request);
    }
    catch (e) {
    result = e.description;
    }

    return result;
    }

    function GetCompList() {
    CompList.innerHTML = InvokeNavWS(baseURL);
    return;
    }
    </script>

    </head>
    <body>
    <p><button type="button" value="Execute" onclick="GetCompList(); return false;" id="btnGetCompList">Get Company List</button></p>
    <form id="CompList"/>
    </body>
    </html>
  • nicetobenicetobe Member Posts: 4
    Please, can anybody post javascript example for creating record in nav ? Or inserting data in current record ? Thanks
  • IsakssonMiIsakssonMi Member Posts: 77
    You don't wanna go straight in to NAV from javascript/site, you should have a web service bridge with some external authentication.. put some auth in the soap-header.. and its easier to let your asmx-service talk to NAV than javascript.. if u go IIS..
Sign In or Register to comment.