We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to specify parameters to an OData query that expects parameters?

Thread ID:

Created:

Updated:

Platform:

Replies:

115961 Mar 6,2014 03:32 AM UTC Mar 11,2014 12:37 PM UTC JavaScript 5
loading
Tags: ejGrid
Xander van der Merwe
Asked On March 6, 2014 03:32 AM UTC

How do I specify parameters on an OData query method? I now understand how to specify a filter, but cannot figure out how to specify parameters? I cannot find this in the online help at all...

Here is a valid odata query with two parameters (serviceId and view) that I am trying to replicate:

http://localhost:30739/Main.svc/GetServiceUsersByService()?serviceId=3&view=%27Default%27&$top=20

I've tried something like the following but it doesn't work:

grid_actionBegin = function (args) {
        var serviceId = 3;
        var view = "Default";
        args.model.query = ej.Query()
            .addParams("serviceId", serviceId)
            .addParams("view", view);
    }
};

Madhu Sudhanan P [Syncfusion]
Replied On March 7, 2014 07:08 AM UTC

Hi Xander,

 

The addParams function is designed to accept parameter values as string and function and hence it is not considering the integer type parameters.

 

We have confirmed that the issue with “Adding integer type custom parameter” is a defect and we have logged a defect report. The fix for this issue will be included in our Volume 1, 2014 release on the month of April.

 

For now we can add the integer type parameter to the url by passing function as the parameter. The parameter function will  return the integer value. Please refer the following code snippet.

 

 

grid_actionBegin = function (args) {

            args.model.query = ej.Query()

                .addParams("serviceId", serviceId)

                .addParams("view", view);

        }

 

function serviceId() { return 3; }

 

function view() { return "Default"; }

 

 

For your convenience, we have created a simple sample please find the sample from the attachment.

 

Please let us know if you have any queries.

 

Regards,

Madhu Sudhanan. P


Attachment: F115967_916f7920.zip

Xander van der Merwe
Replied On March 10, 2014 03:26 AM UTC

Thanks, using functions work, but when the function returns a string you have to return that string enclosed in single quotes or it will not work. For example:

function view() { return "Default"; }    // does NOT work

function view() { return "'Default'"; }  // does work

I'm not sure whether this is a SyncFusion issue/requirement or a Lighswitch OData issue/requirement.

Regards

Madhu Sudhanan P [Syncfusion]
Replied On March 10, 2014 09:30 AM UTC

Hi Xander,

 

The addParams will provide parameters that can be added to the query. While generating query, the parameter types are not considered so single quotes are not added to the string type parameters.

 

If we want to pass the string type parameter through the URL, we have to wrap the parameter with the single quotes as follow.

 

 

function action(args) {

            args.model.query = ej.Query().addParams("view", param2);       

        }

 

function param2() { return "'Default'"; }

 

And hence it will be added in the url as follow.

 

http://localhost:30739/Main.svc/GetServiceUsersByService()?view=%27Default%27

 

 

 

Please let us know if you have any queries.

 

Regards,

Madhu Sudhanan. P


Xander van der Merwe
Replied On March 10, 2014 09:35 AM UTC

OK thanks, so it is by design. 

Might be a good idea to add something about that into your documentation as it took me a little while to work out why the query was giving an "invalid syntax error..." - specifically for Lightswitch developers.

Thank you.

Madhu Sudhanan P [Syncfusion]
Replied On March 11, 2014 12:37 PM UTC

Hi Xander,

 

Ok, thanks for your update.

 

Please get to us back if you require further assistance, we will be glad to help you out.

 

Regards,

Madhu Sudhanan. P


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;