Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, May 3, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Read properties with SDataSingleResourceRequest
Rich Wingerter
Posts: 18
 
Read properties with SDataSingleResourceRequestYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Feb 15 5:55 PM

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?

[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Read properties with SDataSingleResourceRequestYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 11 Feb 15 8:52 PM

You don't need or want the object returned by request.read. Instead, you pass a success delegate (or failure delegate) to request.read and the delegate is invoked and passed the result(s) as an argument. For SDataSingleResourceRequest the success delegate is passed the entry (the entity object requested). So, to read the properties of the returned object you'd structure the code like this:


 


request.read({
success: function(entry) {
// read properties of the object here
// for example, if this is a contact you could get properties like this
var lastName = entry.LastName;
var workPhone = entry.WorkPhone;

// you can see the entire object in the console
console.log(entry)
},
failure: function(data) {
// if an error occurs the "data" object will contain the error details
// if the requested entity does not exist, "data" will contain an error code 404
}
})

 


Make sense? The "entry" here is whatever entity you just requested.

[Reply][Quote]
Rich Wingerter
Posts: 18
 
Re: Read properties with SDataSingleResourceRequestYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 12 Feb 15 10:19 AM

I'd like to use the success delegate but I can't find a way to store the values in any JavaScript location that I can use outside the request.read() function. The original sample put the values in the DOM. I need to process them with other data before I put them in the DOM. So, I need a place outside this call where I can store the results I get from SData that will persist after I return from the function where I'm calling request.read(). None of the approaches I've tried (like storing them in a property of "this") will make them available where I need them.


"Entry" has all the right values. I just don't have a way to keep them after I get them.

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 5/3/2024 3:07:43 AM