Page 1 of 1

Cannot get query_service to populate detail page with local storage mapping

Posted: Sat Jan 03, 2015 9:09 am
by Armand

I have a collection (doctortypes). I populate a list with it. My hidden label is a field TypeID. On click I grab this TypeID and store it in local storage.

On my doctors detail page I invoke query_service to return all doctors for selected type.

On the Before Send event I mapped local storage to query with "where" and my JS is

var test = {"TypeID": "'+ _doctortypid + '"};
return test;

It return blank page. I know that the correct id is returned on click.
My Success event is correctly mapped and works 100% when I delete the Before Send event mapping, but then obviously return the whole dataset.

This is my first appery app. I have really looked at all tutorials I could find.

Thx

Armand


Cannot get query_service to populate detail page with local storage mapping

Posted: Sat Jan 03, 2015 1:35 pm
by Illya Stepanov

Hi Armand -

Please check if you are passing the valid data types and value to the query service.
What result you are getting when testing your service?


Cannot get query_service to populate detail page with local storage mapping

Posted: Sat Jan 03, 2015 1:50 pm
by Armand

Datatype is number. If I put a label on detail page and read storage into it I get correct value of storage back.

If I test query-service with the following script it work 100%

{"TypeID":1}

My local storage is type number.


Cannot get query_service to populate detail page with local storage mapping

Posted: Sat Jan 03, 2015 2:13 pm
by Illya Stepanov

Can you show how exactly you define the storage variable and reading it's value?


Cannot get query_service to populate detail page with local storage mapping

Posted: Sat Jan 03, 2015 6:30 pm
by Armand

In Model and Storage I have declared a variable name: _doctortypid Local storage Type = number.

In master page I have list box with label(doctortypeid) mapped to collection DoctorTypes field TypeID.

On listitem click event action Set Storage Variable. Variable name from drop down is _doctortypid bind to component is checked. Target component is label(doctortypeid)
Property name = Text.

On detail screen on Load event I Invoke Service(restservice1). Restservice is a query_service.

I then mapped the local storage on the Before Send event.
On the Succes event I mapped the body to the page.

I populate the detail page with the storage value and it works 100%, So I am sure that the detail page is getting the correct value.


Cannot get query_service to populate detail page with local storage mapping

Posted: Mon Jan 05, 2015 12:52 am
by Yurii Orishchuk

Hi Armand,

You return an object. But "where" parameter should have "string" type.

So you need to convert your object to "string".

Here is a code:

pre

var currentValue = Apperyio.storage._doctortypid.get();

//Take a look into browser console - to see actual value.
console.log("currentValue = " + currentValue);

var whereObject = {"TypeID": currentValue};

return JSON.stringify(whereObject);

/pre

Regards.


Cannot get query_service to populate detail page with local storage mapping

Posted: Mon Jan 05, 2015 7:54 am
by Armand

Yurii

Thanks, I am almost there. If I read the whereObject into my console the answer is:
whereObject ={"TypeID":"1"}

where the correct answer should be

whereObject ={"TypeID":1}

The number is incorrectly returned as string and not value?


Cannot get query_service to populate detail page with local storage mapping

Posted: Mon Jan 05, 2015 10:44 pm
by Yurii Orishchuk

Hi Armand,

You can parse value to integer with following code to achieve it:

pre

var currentValue = Apperyio.storage._doctortypid.get();

//Parse to int
var currentValue = parseInt(currentValue);

//Take a look into browser console - to see actual value.
console.log("currentValue = " + currentValue);
var whereObject = {"TypeID": currentValue};
return JSON.stringify(whereObject);

/pre

Regards.


Cannot get query_service to populate detail page with local storage mapping

Posted: Tue Jan 06, 2015 7:43 am
by Armand

Thank you very much. It is working now.