Page 1 of 1

Universal Display File Issue

Posted: Mon May 07, 2018 2:06 pm
by mwalter
I know I'm missing something simple, but can't seem to locate it.

I have a universal display file that basically just returns the item description from the item number and location passed.

The UDF works fine in SOAPUI.

I'm basically getting the error that result is null. The actual error is "Cannot read property 'success' of null'.
Here is the javascript that I'm using to invoke the UDF.

Code: Select all

debugger;
ajaxJSON({
url: "/profoundui/universal/facValidItem",
params: {
itemNumber: getObj("txtItemNumber").value,
location: "01"
},
method: "get",
async: true,
handler: function(result) {
  if (result.success) {
    changeElementValue("txtDescription",result.itemDesc);
  }
  else {
    applyProperty("txtItemNumber","focus",true);
    getObj("txtItemNumber").select();
    alert(result.errorDesc);
  }  
}
});

Re: Universal Display File Issue

Posted: Mon May 07, 2018 9:09 pm
by Scott Klement
Mark,

Its not clear why result is coming back null for you. I would suggest using the browser's debugging tools to see what's going on.

I'd start with the "Network" tool to see that the HTTP request is running properly, and that it's returning the proper document.

Re: Universal Display File Issue

Posted: Tue May 08, 2018 8:48 am
by mwalter
Status is 200.

Re: Universal Display File Issue

Posted: Tue May 08, 2018 9:32 am
by mwalter
Ok, I think the problem may be the actual ajax call. I tried to put my RPG for the UDF into debug and it was never invoked. I can see the javascript fire in the Chrome debugger. I'm sure my PUIMAPP file is populated properly. I can even put the url/queryString into a browser and get the proper results. Not sure where to go from here.

Re: Universal Display File Issue

Posted: Tue May 08, 2018 11:14 am
by mwalter
I was wrong. The program is getting invoked because I sent it some bad data, and it abended. So, I'm back to square one. Why is my response null?

I can see the response in the response section of the Chrome network tool in the Developer Tools.

Re: Universal Display File Issue

Posted: Wed May 09, 2018 1:20 pm
by Scott Klement
ajaxJSON will pass null to your handler if the data isn't valid JSON data.

Here's an excerpt from the code inside the ajaxJSON routine:

Code: Select all

    var responseText = ajaxRequest.getResponseText();
    try {
      responseObj = eval("(" + responseText + ")");
    }
    catch(e) {
      callback(null, e);
      return;
    }
    if (async == true) {
      callback(responseObj);
    }
As you can see, it evaluates the JSON data into a JavaScript object in a try/catch group. The only time it calls your handler routine ("callback") and passes null is if the evaluation resulted in an error.

Re: Universal Display File Issue

Posted: Wed May 09, 2018 1:45 pm
by mwalter
Thanks so much, AGAIN, Scott. I wasn't delimiting my character fields.