Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

trying to execute service from javascript

I am trying to execute a query service. The query will change dependant on certain circumstances (what we are searching on).

I figure that there are two ways of doing this:

1) create a different datasource for each query
2) create one datasource and pass it the where clause as a parameter

As I was not sure how to attempt the second one, I tried option 1) first.

The page onload event is the following javascript:
pre
//Set Page Title
var title = localStorage.getItem('category').trim();
console.log("'title = " + title + "'");
(Appery('itemsHeader').text(title));

//Construct service name
var serviceName = title.toLowerCase() + "_items_list";
serviceName = serviceName.trim();
console.log("'Service Name = " + serviceName + "'");

//Execute search service
serviceName.execute({});
/pre

Local Storage "category" = "Beef"
A datasource "beef_items_list" exists with the where clause predefined as {ProductType:"Beef"}

When I load this page, I get the following console output:

pre
'title = Beef' VM2636:208
'Service Name = beef_items_list' VM2636:214
Uncaught TypeError: undefined is not a function VM2636:217
/pre

I am unsure what is causing the error. Also if it is possible to do this with one datasource (passing the where clause as a parameter) can you explain how I would go about this?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

trying to execute service from javascript

Hi Terry,

You want to execute a service named serviceName, while a variable serviceName is of string type, and not a function.

Here is how to execute such service:
prevar myService = this[serviceName];
myService.execute();/pre

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

trying to execute service from javascript

Thanks, that has fixed it!

Return to “Issues”