[CLOSED] direct method returns undefined value

  1. #1

    [CLOSED] direct method returns undefined value

    Hello,
    I have a direct method which gets 2 arguments and returns a value (string). While I can see that the direct method is called and the return value "result" is as expected (the alert function prints it with the correct value), the value in the HTML is 'undefined'

    Handler="
        this.body.dom.innerHTML = String.format('{0}',(#{QueriesStore1}.getAt(rowIndex).get('PtId') !=null? #{DirectMethods}.callFNGetPtidPrfx(#{QueriesStore1}.getAt(rowIndex).get('SiteId'),#{QueriesStore1}.getAt(rowIndex).get('PtId'),{
                     success: function (result) {
                         alert(result);
                         return result;  
                     }
                 }):'-')
    The direct method:
    [DirectMethod]
            public string callFNGetPtidPrfx(int siteid, int ptid)
            {
                DAL.CDataContext dc = new CDataContext(); //the arguments have the correct value here
                return dc.fn_GetPtid(100, siteid, ptid);
            }
    Last edited by fabricio.murta; Aug 18, 2017 at 10:13 PM.
  2. #2
    Hello @atroul!

    That's an assynchronous call. You have to bind the result to an outside variable during the success (or failure) function execution, it won't be returning anything at call-time.

    In other words, you should rather

    #{DirectMethods}.callFNGetPtidPrfx(#{QueriesStore1}.getAt(rowIndex).get('SiteId'),#{QueriesStore1}.getAt(rowIndex).get('PtId'),{
        success: function(result) {
            this.body.dom.innerHTML = result;
        }
    });
    instead of

    this.body.dom.innerHTML = #{DirectMethods}.callFNGetPtidPrfx(#{QueriesStore1}.getAt(rowIndex).get('SiteId'),#{QueriesStore1}.getAt(rowIndex).get('PtId'),{
        success: function(result) {
            return result;
        }
    });
    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello @atroul!

    It's been a while since we last responded to your inquiry here, and still no feedback from you. Do you happen to still need help with this, or was the answer enough to fulfill an adequate response to your question?

    You may already know, but just in case: if you don't reply here, we'll assume you don't need further help and mark the thread as closed. Well, this won't be preventing you from posting back here whenever you are able to, anyway.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Direct Method - App.direct undefined
    By registrator in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 23, 2014, 1:47 PM
  2. Replies: 2
    Last Post: May 13, 2014, 8:52 AM
  3. [CLOSED] Output Cache issue with Direct Method / Direct Event
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 18
    Last Post: Mar 01, 2013, 5:03 AM
  4. Direct method and direct event over SSL?
    By dimitar in forum 1.x Help
    Replies: 0
    Last Post: Oct 08, 2011, 8:09 PM
  5. [CLOSED] e.getkey() returns undefined?
    By JonG in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 10, 2010, 11:29 AM

Tags for this Thread

Posting Permissions