I am reading SData using JavaScript in a Welcome screen widget. The SData read appears to return valid data, but I’m having trouble capturing this and storing it in a JavaScript variable.
I used Sage.SData.Client.SDataService() and Sage.SData.Client.SDataSingleResourceRequest() to construct a query like:
http://localhost:3333/sdata/slx/dynamic/-/contacts(%22CRATYA10000V%22)?_includeContent=true&select=FirstName%2CLastName%2CWorkPhone%2CEmail
This goes in a request variable. When I do:
var rtn = request.read({success: function(entry) {console.log(entry); }, failure: function(data) {console.error(data);} });
I get a value for rtn that seems to have valid data in it. In fact, if I do:
console.log(rtn);
I get
HTMLHttpRequest {values}
(where values is a list of things like statusText: "", etc.) on the console in Chrome and I can open it and see a long string in its response property. (The note says “Object state below is captured upon first expansion”.)
But if I try to do rtn.response in my code I get the null string, and in fact rtn.response.length is 0.
How do I access the data returned by request.read()? Anything in the success branch is an argument to the function and scoping prevents me from putting it into any kind of data structure. I don’t seem to have any way to access the data returned by the function. All the examples I have are in C#, not JavaScript. In C#, apparently you could cast this return variable as AtomFeed and then extract its payload. I’d like to extract the payload in JavaScript. I don’t care what format—json or XML—I just care about getting the values of the properties for the resource I’m looking up.
I haven’t found any documentation on the request.read() function that applies to JavaScript. If I enumerate the properties for rtn they look correct. For example, it has .response and .responseText and even .responseXML properties. But the values are all null.
Does anyone know how to use SData with JavaScript and get the values out? |