Ribbon button JavaScript fails to return bool from web service (ASMX) call RRS feed

  • Question

  • I'm having trouble using a .Net ASMX web service that returns a Boolean to control a ribbon buttons enable property. I think I am doing the JavaScript wrong, but I cannot see what I am doing wrong.  I need this to call out to a web service, as the data is not in CRM that I am checking.  So I have web service that verifies if data is in another database, and if so I enabled a ribbon button.  That ribbon button then calls out and throws up a popup window to display the data from another application. 

    Everything is working except that when I call out to the webservice, it is always returning true.  I suspect that is because I am not evaluating the value returned from the web service, but just the response object itself. In other words, if the call doesn't fail and the object is a valid object without a value of null, o , false, etc. it returns true.  But I need to evaluate if actual value returned by the web service. I have tested the web service sepeately and it works correctly and returns true/false as it should.  So my issue has to be in how I have coded the JavaScript .ajax call and how it is returning and handing the on-success function.

    I'm hoping someone can point out what I am doing wrong here. 

    Here's the .Net ASMX web service method.  Note that I am just returning a bool.  I have removed the script method attribute on some tests and it doesn't seem to do anything differently.  So I don't know for sure if I need it or not.

            [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
            public bool IsContract(string id, string key)

    Here's the JavaScript:

                type: "GET",
                async: false,   // Fails to work without it!
                url: url,
                data: parameters,
                success: function(resp) {
                    if (resp)
                        enableButton = true;
                        enableButton = false;
                error: function () {
                    enableButton = false;
            return enableButton;

    So what am I doing wrong?  If throw up an alert window for the response, it is of type object.  But I would expect it to be a Boolean.  I did try response.d to return the Boolean value from a JSON object, but that ends up being undefined. So I am not sure how to access the response oject and access the Boolean value being returned.

    Any suggestions or examples are much appreciated. 

    Best regards,

    Jon Gregory Rothlander

    Wednesday, October 8, 2014 8:31 PM


All replies

  • hi Jon,

    please put a break point or alert on resp inside success and see the actual value.

    either your resp variable is declared true and returns true without going into function or if (resp)
                        is evaluated to true.



    Wednesday, October 8, 2014 9:20 PM
  • Hello,

    Did you try to check (resp.responseText), if your code is working fine to debug and check resp object.

    Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, October 9, 2014 12:54 AM
  • Under arguments [2], the response contains "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<boolean xmlns=\"DHI_CRM_WebService\">false</boolean>".

    This is the correct value.  If I test it with a result that is true, the value returned is true.  So what I don't understand is how to correctly access this value in the JavaScript. 

    How would you go about accessing the response object from a web method.  It's been awhile since I last had to do anything significant in JavaScript.  So I suspect I am missing something simple here. 

    Jon Gregory Rothlander

    Thursday, October 9, 2014 2:19 PM
  • I suspect this may be the cross domain issue. Check the console tab in chrome by hitting F12.

    Padmakar - http://gpadmakar.blogspot.com

    • Marked as answer by jonrothlander Tuesday, November 25, 2014 10:05 PM
    Thursday, October 9, 2014 11:25 PM